Committed by
Thomas Vachuska
[ONOS-4411,ONOS-4413,ONOS-4526] Yang Enumeration Translator and Defect fixes.
Change-Id: Ie5b6b5d6d6df283a57ae06b1979f0d03022f3baf
Showing
33 changed files
with
777 additions
and
281 deletions
| ... | @@ -78,6 +78,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -78,6 +78,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
| 78 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 78 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
| 79 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 79 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
| 80 | import static org.onosproject.yangutils.utils.YangConstructType.ENUM_DATA; | 80 | import static org.onosproject.yangutils.utils.YangConstructType.ENUM_DATA; |
| 81 | +import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; | ||
| 82 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
| 81 | 83 | ||
| 82 | /** | 84 | /** |
| 83 | * Represents listener based call back function corresponding to the "enum" rule | 85 | * Represents listener based call back function corresponding to the "enum" rule |
| ... | @@ -104,10 +106,18 @@ public final class EnumListener { | ... | @@ -104,10 +106,18 @@ public final class EnumListener { |
| 104 | checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUM_DATA, ctx.string().getText(), ENTRY); | 106 | checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUM_DATA, ctx.string().getText(), ENTRY); |
| 105 | 107 | ||
| 106 | YangEnum enumNode = new YangEnum(); | 108 | YangEnum enumNode = new YangEnum(); |
| 107 | - enumNode.setNamedValue(ctx.string().getText()); | 109 | + enumNode.setNamedValue(getValidNamedValue(ctx.string().getText())); |
| 108 | listener.getParsedDataStack().push(enumNode); | 110 | listener.getParsedDataStack().push(enumNode); |
| 109 | } | 111 | } |
| 110 | 112 | ||
| 113 | + /* Removes quotes from the enum name if present.*/ | ||
| 114 | + private static String getValidNamedValue(String name) { | ||
| 115 | + if (name.contains(QUOTES)) { | ||
| 116 | + name = name.replace(QUOTES, EMPTY_STRING); | ||
| 117 | + } | ||
| 118 | + return name; | ||
| 119 | + } | ||
| 120 | + | ||
| 111 | /** | 121 | /** |
| 112 | * It is called when parser exits from grammar rule (enum), it perform | 122 | * It is called when parser exits from grammar rule (enum), it perform |
| 113 | * validations and update the data model tree. | 123 | * validations and update the data model tree. |
| ... | @@ -163,7 +173,8 @@ public final class EnumListener { | ... | @@ -163,7 +173,8 @@ public final class EnumListener { |
| 163 | } | 173 | } |
| 164 | } else { | 174 | } else { |
| 165 | throw new ParserException( | 175 | throw new ParserException( |
| 166 | - constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT)); | 176 | + constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUM_DATA, ctx.string().getText(), |
| 177 | + EXIT)); | ||
| 167 | } | 178 | } |
| 168 | } | 179 | } |
| 169 | } | 180 | } | ... | ... |
| ... | @@ -158,6 +158,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -158,6 +158,7 @@ public class YangUtilManager extends AbstractMojo { |
| 158 | logInfo = logInfo + NEW_LINE + e.getMessage(); | 158 | logInfo = logInfo + NEW_LINE + e.getMessage(); |
| 159 | } | 159 | } |
| 160 | getLog().info(logInfo); | 160 | getLog().info(logInfo); |
| 161 | + throw e; | ||
| 161 | } | 162 | } |
| 162 | } | 163 | } |
| 163 | 164 | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
| ... | @@ -166,6 +166,7 @@ public class JavaQualifiedTypeInfo | ... | @@ -166,6 +166,7 @@ public class JavaQualifiedTypeInfo |
| 166 | * @return return the import info for this attribute | 166 | * @return return the import info for this attribute |
| 167 | */ | 167 | */ |
| 168 | public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo) { | 168 | public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo) { |
| 169 | + | ||
| 169 | /* | 170 | /* |
| 170 | * Get the java qualified type information for the wrapper classes and | 171 | * Get the java qualified type information for the wrapper classes and |
| 171 | * set it in new java attribute information. | 172 | * set it in new java attribute information. |
| ... | @@ -178,7 +179,6 @@ public class JavaQualifiedTypeInfo | ... | @@ -178,7 +179,6 @@ public class JavaQualifiedTypeInfo |
| 178 | return qualifiedInfoOfFromString; | 179 | return qualifiedInfoOfFromString; |
| 179 | } | 180 | } |
| 180 | 181 | ||
| 181 | - | ||
| 182 | @Override | 182 | @Override |
| 183 | public int hashCode() { | 183 | public int hashCode() { |
| 184 | return Objects.hash(pkgInfo, classInfo); | 184 | return Objects.hash(pkgInfo, classInfo); | ... | ... |
| ... | @@ -51,7 +51,6 @@ public class TempJavaBeanFragmentFiles | ... | @@ -51,7 +51,6 @@ public class TempJavaBeanFragmentFiles |
| 51 | 51 | ||
| 52 | super(javaFileInfo); | 52 | super(javaFileInfo); |
| 53 | 53 | ||
| 54 | - | ||
| 55 | /* | 54 | /* |
| 56 | * Initialize getterImpl, attributes, constructor, hash code, equals and | 55 | * Initialize getterImpl, attributes, constructor, hash code, equals and |
| 57 | * to strings when generation file type matches to impl class mask. | 56 | * to strings when generation file type matches to impl class mask. |
| ... | @@ -98,6 +97,7 @@ public class TempJavaBeanFragmentFiles | ... | @@ -98,6 +97,7 @@ public class TempJavaBeanFragmentFiles |
| 98 | * files | 97 | * files |
| 99 | * @throws IOException IO operation fail | 98 | * @throws IOException IO operation fail |
| 100 | */ | 99 | */ |
| 100 | + @Override | ||
| 101 | void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) | 101 | void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) |
| 102 | throws IOException { | 102 | throws IOException { |
| 103 | super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo); | 103 | super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo); |
| ... | @@ -124,5 +124,4 @@ public class TempJavaBeanFragmentFiles | ... | @@ -124,5 +124,4 @@ public class TempJavaBeanFragmentFiles |
| 124 | super.freeTemporaryResources(isErrorOccurred); | 124 | super.freeTemporaryResources(isErrorOccurred); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | - | ||
| 128 | } | 127 | } | ... | ... |
| ... | @@ -67,7 +67,6 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -67,7 +67,6 @@ public class TempJavaCodeFragmentFiles { |
| 67 | */ | 67 | */ |
| 68 | private TempJavaEventListenerFragmentFiles eventListenerTempFiles; | 68 | private TempJavaEventListenerFragmentFiles eventListenerTempFiles; |
| 69 | 69 | ||
| 70 | - | ||
| 71 | /** | 70 | /** |
| 72 | * Creates an instance of temporary java code fragment. | 71 | * Creates an instance of temporary java code fragment. |
| 73 | * | 72 | * |
| ... | @@ -126,7 +125,6 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -126,7 +125,6 @@ public class TempJavaCodeFragmentFiles { |
| 126 | this.beanTempFiles = beanTempFiles; | 125 | this.beanTempFiles = beanTempFiles; |
| 127 | } | 126 | } |
| 128 | 127 | ||
| 129 | - | ||
| 130 | /** | 128 | /** |
| 131 | * Retrieves the temp file handle for data type file generation. | 129 | * Retrieves the temp file handle for data type file generation. |
| 132 | * | 130 | * |
| ... | @@ -136,7 +134,6 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -136,7 +134,6 @@ public class TempJavaCodeFragmentFiles { |
| 136 | return typeTempFiles; | 134 | return typeTempFiles; |
| 137 | } | 135 | } |
| 138 | 136 | ||
| 139 | - | ||
| 140 | /** | 137 | /** |
| 141 | * Sets temp file handle for data type file generation. | 138 | * Sets temp file handle for data type file generation. |
| 142 | * | 139 | * |
| ... | @@ -234,23 +231,29 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -234,23 +231,29 @@ public class TempJavaCodeFragmentFiles { |
| 234 | getBeanTempFiles().generateJavaFile(fileType, curNode); | 231 | getBeanTempFiles().generateJavaFile(fileType, curNode); |
| 235 | } | 232 | } |
| 236 | 233 | ||
| 237 | - /** | 234 | + /* |
| 238 | * Creates user defined data type class file. | 235 | * Creates user defined data type class file. |
| 239 | */ | 236 | */ |
| 240 | if ((fileType & GENERATE_TYPE_CLASS) != 0) { | 237 | if ((fileType & GENERATE_TYPE_CLASS) != 0) { |
| 241 | getTypeTempFiles().generateJavaFile(fileType, curNode); | 238 | getTypeTempFiles().generateJavaFile(fileType, curNode); |
| 242 | } | 239 | } |
| 243 | 240 | ||
| 244 | - | 241 | + /* |
| 242 | + * Creats service and manager class file. | ||
| 243 | + */ | ||
| 245 | if (fileType == GENERATE_SERVICE_AND_MANAGER) { | 244 | if (fileType == GENERATE_SERVICE_AND_MANAGER) { |
| 246 | - | ||
| 247 | getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode); | 245 | getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode); |
| 246 | + } | ||
| 248 | 247 | ||
| 249 | - | 248 | + /* |
| 249 | + * Creats enumeration class file. | ||
| 250 | + */ | ||
| 251 | + if (fileType == GENERATE_ENUM_CLASS) { | ||
| 252 | + getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode); | ||
| 250 | } | 253 | } |
| 251 | 254 | ||
| 252 | if ((fileType & GENERATE_EVENT_CLASS) != 0) { | 255 | if ((fileType & GENERATE_EVENT_CLASS) != 0) { |
| 253 | - /** | 256 | + /* |
| 254 | * Creates event class file. | 257 | * Creates event class file. |
| 255 | */ | 258 | */ |
| 256 | if (getEventTempFiles() != null) { | 259 | if (getEventTempFiles() != null) { |
| ... | @@ -350,7 +353,6 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -350,7 +353,6 @@ public class TempJavaCodeFragmentFiles { |
| 350 | throw new TranslatorException("default constructor should not be added"); | 353 | throw new TranslatorException("default constructor should not be added"); |
| 351 | } | 354 | } |
| 352 | 355 | ||
| 353 | - | ||
| 354 | /** | 356 | /** |
| 355 | * Adds build method's implementation for class. | 357 | * Adds build method's implementation for class. |
| 356 | * | 358 | * |
| ... | @@ -397,22 +399,4 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -397,22 +399,4 @@ public class TempJavaCodeFragmentFiles { |
| 397 | } | 399 | } |
| 398 | } | 400 | } |
| 399 | 401 | ||
| 400 | - | ||
| 401 | - /** | ||
| 402 | - * Adds enum attributes to temporary files. | ||
| 403 | - * | ||
| 404 | - * @param curNode current YANG node | ||
| 405 | - * @throws IOException when fails to do IO operations | ||
| 406 | - */ | ||
| 407 | - public void addEnumAttributeToTempFiles(YangNode curNode) | ||
| 408 | - throws IOException { | ||
| 409 | - | ||
| 410 | - if (getEnumerationTempFiles() != null) { | ||
| 411 | - getEnumerationTempFiles().addEnumAttributeToTempFiles(curNode); | ||
| 412 | - return; | ||
| 413 | - } | ||
| 414 | - | ||
| 415 | - throw new TranslatorException("build should not be added"); | ||
| 416 | - } | ||
| 417 | - | ||
| 418 | } | 402 | } | ... | ... |
| ... | @@ -15,14 +15,68 @@ | ... | @@ -15,14 +15,68 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.yangutils.translator.tojava; | 16 | package org.onosproject.yangutils.translator.tojava; |
| 17 | 17 | ||
| 18 | +import java.io.File; | ||
| 18 | import java.io.IOException; | 19 | import java.io.IOException; |
| 20 | +import java.util.ArrayList; | ||
| 21 | +import java.util.HashMap; | ||
| 22 | +import java.util.List; | ||
| 23 | +import java.util.Map; | ||
| 24 | + | ||
| 25 | +import org.onosproject.yangutils.datamodel.YangDataTypes; | ||
| 26 | +import org.onosproject.yangutils.datamodel.YangEnum; | ||
| 27 | +import org.onosproject.yangutils.datamodel.YangEnumeration; | ||
| 28 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
| 29 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
| 30 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType; | ||
| 31 | + | ||
| 32 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; | ||
| 33 | +import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; | ||
| 34 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString; | ||
| 35 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile; | ||
| 36 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; | ||
| 37 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
| 38 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | ||
| 19 | 39 | ||
| 20 | /** | 40 | /** |
| 21 | * Represents implementation of java code fragments temporary implementations. | 41 | * Represents implementation of java code fragments temporary implementations. |
| 22 | * Maintains the temp files required specific for enumeration java snippet generation. | 42 | * Maintains the temp files required specific for enumeration java snippet generation. |
| 23 | */ | 43 | */ |
| 24 | -public class TempJavaEnumerationFragmentFiles | 44 | +public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
| 25 | - extends TempJavaFragmentFiles { | 45 | + |
| 46 | + /** | ||
| 47 | + * File name for temporary enum class. | ||
| 48 | + */ | ||
| 49 | + private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass"; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * File name for enum class file name suffix. | ||
| 53 | + */ | ||
| 54 | + private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * Current enum's value. | ||
| 58 | + */ | ||
| 59 | + private int enumValue; | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * Contains data of enumSet. | ||
| 63 | + */ | ||
| 64 | + private Map<String, Integer> enumStringMap = new HashMap<>(); | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * Contains data of enumSet. | ||
| 68 | + */ | ||
| 69 | + private List<String> enumStringList; | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * Temporary file handle for enum class file. | ||
| 73 | + */ | ||
| 74 | + private File enumClassTempFileHandle; | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * Java file handle for enum class. | ||
| 78 | + */ | ||
| 79 | + private File enumClassJavaFileHandle; | ||
| 26 | 80 | ||
| 27 | /** | 81 | /** |
| 28 | * Creates an instance of temporary java code fragment. | 82 | * Creates an instance of temporary java code fragment. |
| ... | @@ -32,6 +86,212 @@ public class TempJavaEnumerationFragmentFiles | ... | @@ -32,6 +86,212 @@ public class TempJavaEnumerationFragmentFiles |
| 32 | */ | 86 | */ |
| 33 | public TempJavaEnumerationFragmentFiles(JavaFileInfo javaFileInfo) | 87 | public TempJavaEnumerationFragmentFiles(JavaFileInfo javaFileInfo) |
| 34 | throws IOException { | 88 | throws IOException { |
| 89 | + | ||
| 35 | super(javaFileInfo); | 90 | super(javaFileInfo); |
| 91 | + setEnumSetJavaMap(new HashMap<>()); | ||
| 92 | + setEnumStringList(new ArrayList<>()); | ||
| 93 | + /* | ||
| 94 | + * Initialize enum when generation file type matches to enum class mask. | ||
| 95 | + */ | ||
| 96 | + addGeneratedTempFile(ENUM_IMPL_MASK); | ||
| 97 | + setEnumClassTempFileHandle(getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME)); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * Returns enum class java file handle. | ||
| 102 | + * | ||
| 103 | + * @return enum class java file handle | ||
| 104 | + */ | ||
| 105 | + public File getEnumClassJavaFileHandle() { | ||
| 106 | + return enumClassJavaFileHandle; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * Sets enum class java file handle. | ||
| 111 | + * | ||
| 112 | + * @param enumClassJavaFileHandle enum class java file handle | ||
| 113 | + */ | ||
| 114 | + private void setEnumClassJavaFileHandle(File enumClassJavaFileHandle) { | ||
| 115 | + this.enumClassJavaFileHandle = enumClassJavaFileHandle; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * Returns enum's value. | ||
| 120 | + * | ||
| 121 | + * @return enum's value | ||
| 122 | + */ | ||
| 123 | + private int getEnumValue() { | ||
| 124 | + return enumValue; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * Sets enum's value. | ||
| 129 | + * | ||
| 130 | + * @param enumValue enum's value | ||
| 131 | + */ | ||
| 132 | + private void setEnumValue(int enumValue) { | ||
| 133 | + this.enumValue = enumValue; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + /** | ||
| 137 | + * Returns enum set java map. | ||
| 138 | + * | ||
| 139 | + * @return the enum set java map | ||
| 140 | + */ | ||
| 141 | + public Map<String, Integer> getEnumSetJavaMap() { | ||
| 142 | + return enumStringMap; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * Sets enum set java map. | ||
| 147 | + * | ||
| 148 | + * @param map the enum set java map to set | ||
| 149 | + */ | ||
| 150 | + private void setEnumSetJavaMap(Map<String, Integer> map) { | ||
| 151 | + this.enumStringMap = map; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + /** | ||
| 155 | + * Returns temporary file handle for enum class file. | ||
| 156 | + * | ||
| 157 | + * @return temporary file handle for enum class file | ||
| 158 | + */ | ||
| 159 | + public File getEnumClassTempFileHandle() { | ||
| 160 | + return enumClassTempFileHandle; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * Sets temporary file handle for enum class file. | ||
| 165 | + * | ||
| 166 | + * @param enumClassTempFileHandle temporary file handle for enum class file | ||
| 167 | + */ | ||
| 168 | + private void setEnumClassTempFileHandle(File enumClassTempFileHandle) { | ||
| 169 | + this.enumClassTempFileHandle = enumClassTempFileHandle; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + /** | ||
| 173 | + * Adds enum class attributes to temporary file. | ||
| 174 | + * | ||
| 175 | + * @param curEnumInfo current YANG enum | ||
| 176 | + * @throws IOException when fails to do IO operations. | ||
| 177 | + */ | ||
| 178 | + private void addAttributesForEnumClass(String curEnumName) throws IOException { | ||
| 179 | + appendToFile(getEnumClassTempFileHandle(), generateEnumAttributeString(curEnumName, getEnumValue())); | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + /** | ||
| 183 | + * Adds enum attributes to temporary files. | ||
| 184 | + * | ||
| 185 | + * @param curNode current YANG node | ||
| 186 | + * @throws IOException when fails to do IO operations | ||
| 187 | + */ | ||
| 188 | + public void addEnumAttributeToTempFiles(YangNode curNode) throws IOException { | ||
| 189 | + | ||
| 190 | + super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum()); | ||
| 191 | + if (curNode instanceof YangEnumeration) { | ||
| 192 | + YangEnumeration enumeration = (YangEnumeration) curNode; | ||
| 193 | + for (YangEnum curEnum : enumeration.getEnumSet()) { | ||
| 194 | + setEnumValue(curEnum.getValue()); | ||
| 195 | + addToEnumStringList(curEnum.getNamedValue()); | ||
| 196 | + addToEnumSetJavaMap(curEnum.getNamedValue(), curEnum.getValue()); | ||
| 197 | + addJavaSnippetInfoToApplicableTempFiles(curEnum.getNamedValue()); | ||
| 198 | + } | ||
| 199 | + } else { | ||
| 200 | + throw new TranslatorException("current node should be of enumeration type."); | ||
| 201 | + } | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + /** | ||
| 205 | + * Returns java attribute for enum class. | ||
| 206 | + * | ||
| 207 | + * @return java attribute | ||
| 208 | + */ | ||
| 209 | + public JavaAttributeInfo getJavaAttributeForEnum() { | ||
| 210 | + YangJavaType<?> javaType = new YangJavaType<>(); | ||
| 211 | + javaType.setDataType(YangDataTypes.INT32); | ||
| 212 | + javaType.setDataTypeName("int"); | ||
| 213 | + javaType.updateJavaQualifiedInfo(); | ||
| 214 | + return getAttributeInfoForTheData( | ||
| 215 | + javaType.getJavaQualifiedInfo(), | ||
| 216 | + javaType.getDataTypeName(), javaType, | ||
| 217 | + getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()), | ||
| 218 | + false); | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + /** | ||
| 222 | + * Adds current enum name to java list. | ||
| 223 | + * | ||
| 224 | + * @param curEnumName current enum name | ||
| 225 | + */ | ||
| 226 | + private void addToEnumSetJavaMap(String curEnumName, int value) { | ||
| 227 | + getEnumSetJavaMap().put(curEnumName.toUpperCase(), value); | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + /** | ||
| 231 | + * Adds the new attribute info to the target generated temporary files. | ||
| 232 | + * | ||
| 233 | + * @param curEnumName the attribute name that needs to be added to temporary | ||
| 234 | + * files | ||
| 235 | + * @throws IOException IO operation fail | ||
| 236 | + */ | ||
| 237 | + void addJavaSnippetInfoToApplicableTempFiles(String curEnumName) throws IOException { | ||
| 238 | + addAttributesForEnumClass(curEnumName); | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + /** | ||
| 242 | + * Constructs java code exit. | ||
| 243 | + * | ||
| 244 | + * @param fileType generated file type | ||
| 245 | + * @param curNode current YANG node | ||
| 246 | + * @throws IOException when fails to generate java files | ||
| 247 | + */ | ||
| 248 | + @Override | ||
| 249 | + public void generateJavaFile(int fileType, YangNode curNode) throws IOException { | ||
| 250 | + createPackage(curNode); | ||
| 251 | + setEnumClassJavaFileHandle(getJavaFileHandle(getJavaClassName(ENUM_CLASS_FILE_NAME_SUFFIX))); | ||
| 252 | + setEnumClassJavaFileHandle(generateEnumClassFile(getEnumClassJavaFileHandle(), curNode)); | ||
| 253 | + freeTemporaryResources(false); | ||
| 254 | + } | ||
| 255 | + | ||
| 256 | + /** | ||
| 257 | + * Removes all temporary file handles. | ||
| 258 | + * | ||
| 259 | + * @param isErrorOccurred when translator fails to generate java files we | ||
| 260 | + * need to close all open file handles include temporary files | ||
| 261 | + * and java files. | ||
| 262 | + * @throws IOException when failed to delete the temporary files | ||
| 263 | + */ | ||
| 264 | + @Override | ||
| 265 | + public void freeTemporaryResources(boolean isErrorOccurred) throws IOException { | ||
| 266 | + closeFile(getEnumClassJavaFileHandle(), isErrorOccurred); | ||
| 267 | + closeFile(getEnumClassTempFileHandle(), true); | ||
| 268 | + super.freeTemporaryResources(isErrorOccurred); | ||
| 269 | + } | ||
| 270 | + | ||
| 271 | + /** | ||
| 272 | + * Adds to enum string list. | ||
| 273 | + * | ||
| 274 | + * @param curEnumValue current enum value | ||
| 275 | + */ | ||
| 276 | + private void addToEnumStringList(String curEnumValue) { | ||
| 277 | + getEnumStringList().add(curEnumValue.toUpperCase()); | ||
| 278 | + } | ||
| 279 | + | ||
| 280 | + /** | ||
| 281 | + * Returns enum string list. | ||
| 282 | + * | ||
| 283 | + * @return the enumStringList | ||
| 284 | + */ | ||
| 285 | + public List<String> getEnumStringList() { | ||
| 286 | + return enumStringList; | ||
| 287 | + } | ||
| 288 | + | ||
| 289 | + /** | ||
| 290 | + * Sets enum string list. | ||
| 291 | + * | ||
| 292 | + * @param enumStringList the enumStringList to set | ||
| 293 | + */ | ||
| 294 | + public void setEnumStringList(List<String> enumStringList) { | ||
| 295 | + this.enumStringList = enumStringList; | ||
| 36 | } | 296 | } |
| 37 | } | 297 | } | ... | ... |
| ... | @@ -56,7 +56,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -56,7 +56,7 @@ public class TempJavaEventFragmentFiles |
| 56 | setExtendsList(new ArrayList<>()); | 56 | setExtendsList(new ArrayList<>()); |
| 57 | setJavaImportData(new JavaImportData()); | 57 | setJavaImportData(new JavaImportData()); |
| 58 | setJavaFileInfo(javaFileInfo); | 58 | setJavaFileInfo(javaFileInfo); |
| 59 | - clearGeneratedTempFileMask(); | 59 | + |
| 60 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), | 60 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), |
| 61 | getJavaFileInfo().getPackageFilePath())); | 61 | getJavaFileInfo().getPackageFilePath())); |
| 62 | 62 | ||
| ... | @@ -80,7 +80,6 @@ public class TempJavaEventFragmentFiles | ... | @@ -80,7 +80,6 @@ public class TempJavaEventFragmentFiles |
| 80 | this.eventJavaFileHandle = eventJavaFileHandle; | 80 | this.eventJavaFileHandle = eventJavaFileHandle; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | - | ||
| 84 | /** | 83 | /** |
| 85 | * Constructs java code exit. | 84 | * Constructs java code exit. |
| 86 | * | 85 | * |
| ... | @@ -88,6 +87,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -88,6 +87,7 @@ public class TempJavaEventFragmentFiles |
| 88 | * @param curNode current YANG node | 87 | * @param curNode current YANG node |
| 89 | * @throws IOException when fails to generate java files | 88 | * @throws IOException when fails to generate java files |
| 90 | */ | 89 | */ |
| 90 | + @Override | ||
| 91 | public void generateJavaFile(int fileType, YangNode curNode) | 91 | public void generateJavaFile(int fileType, YangNode curNode) |
| 92 | throws IOException { | 92 | throws IOException { |
| 93 | 93 | ||
| ... | @@ -113,6 +113,7 @@ public class TempJavaEventFragmentFiles | ... | @@ -113,6 +113,7 @@ public class TempJavaEventFragmentFiles |
| 113 | * and java files. | 113 | * and java files. |
| 114 | * @throws IOException when failed to delete the temporary files | 114 | * @throws IOException when failed to delete the temporary files |
| 115 | */ | 115 | */ |
| 116 | + @Override | ||
| 116 | public void freeTemporaryResources(boolean isErrorOccurred) | 117 | public void freeTemporaryResources(boolean isErrorOccurred) |
| 117 | throws IOException { | 118 | throws IOException { |
| 118 | boolean isError = isErrorOccurred; | 119 | boolean isError = isErrorOccurred; |
| ... | @@ -122,5 +123,6 @@ public class TempJavaEventFragmentFiles | ... | @@ -122,5 +123,6 @@ public class TempJavaEventFragmentFiles |
| 122 | closeFile(getEventJavaFileHandle(), isError); | 123 | closeFile(getEventJavaFileHandle(), isError); |
| 123 | 124 | ||
| 124 | super.freeTemporaryResources(isErrorOccurred); | 125 | super.freeTemporaryResources(isErrorOccurred); |
| 126 | + | ||
| 125 | } | 127 | } |
| 126 | } | 128 | } | ... | ... |
| ... | @@ -56,7 +56,6 @@ public class TempJavaEventListenerFragmentFiles | ... | @@ -56,7 +56,6 @@ public class TempJavaEventListenerFragmentFiles |
| 56 | setExtendsList(new ArrayList<>()); | 56 | setExtendsList(new ArrayList<>()); |
| 57 | setJavaImportData(new JavaImportData()); | 57 | setJavaImportData(new JavaImportData()); |
| 58 | setJavaFileInfo(javaFileInfo); | 58 | setJavaFileInfo(javaFileInfo); |
| 59 | - clearGeneratedTempFileMask(); | ||
| 60 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), | 59 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), |
| 61 | getJavaFileInfo().getPackageFilePath())); | 60 | getJavaFileInfo().getPackageFilePath())); |
| 62 | } | 61 | } |
| ... | @@ -79,7 +78,6 @@ public class TempJavaEventListenerFragmentFiles | ... | @@ -79,7 +78,6 @@ public class TempJavaEventListenerFragmentFiles |
| 79 | this.eventListenerJavaFileHandle = eventListenerJavaFileHandle; | 78 | this.eventListenerJavaFileHandle = eventListenerJavaFileHandle; |
| 80 | } | 79 | } |
| 81 | 80 | ||
| 82 | - | ||
| 83 | /** | 81 | /** |
| 84 | * Constructs java code exit. | 82 | * Constructs java code exit. |
| 85 | * | 83 | * |
| ... | @@ -87,6 +85,7 @@ public class TempJavaEventListenerFragmentFiles | ... | @@ -87,6 +85,7 @@ public class TempJavaEventListenerFragmentFiles |
| 87 | * @param curNode current YANG node | 85 | * @param curNode current YANG node |
| 88 | * @throws IOException when fails to generate java files | 86 | * @throws IOException when fails to generate java files |
| 89 | */ | 87 | */ |
| 88 | + @Override | ||
| 90 | public void generateJavaFile(int fileType, YangNode curNode) | 89 | public void generateJavaFile(int fileType, YangNode curNode) |
| 91 | throws IOException { | 90 | throws IOException { |
| 92 | 91 | ||
| ... | @@ -112,6 +111,7 @@ public class TempJavaEventListenerFragmentFiles | ... | @@ -112,6 +111,7 @@ public class TempJavaEventListenerFragmentFiles |
| 112 | * and java files. | 111 | * and java files. |
| 113 | * @throws IOException when failed to delete the temporary files | 112 | * @throws IOException when failed to delete the temporary files |
| 114 | */ | 113 | */ |
| 114 | + @Override | ||
| 115 | public void freeTemporaryResources(boolean isErrorOccurred) | 115 | public void freeTemporaryResources(boolean isErrorOccurred) |
| 116 | throws IOException { | 116 | throws IOException { |
| 117 | boolean isError = isErrorOccurred; | 117 | boolean isError = isErrorOccurred; | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
This diff is collapsed. Click to expand it.
| ... | @@ -33,9 +33,11 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator | ... | @@ -33,9 +33,11 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator |
| 33 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; | 33 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; |
| 34 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; | 34 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; |
| 35 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; | 35 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
| 36 | -import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils | 36 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended; |
| 37 | - .isHasAugmentationExtended; | 37 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
| 38 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
| 39 | +import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME; | ||
| 40 | +import static org.onosproject.yangutils.utils.UtilConstants.VOID; | ||
| 39 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | 41 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
| 40 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc; | 42 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc; |
| 41 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | 43 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
| ... | @@ -180,12 +182,13 @@ public class TempJavaServiceFragmentFiles | ... | @@ -180,12 +182,13 @@ public class TempJavaServiceFragmentFiles |
| 180 | } | 182 | } |
| 181 | 183 | ||
| 182 | /** | 184 | /** |
| 183 | - * Constructs java code exit. | 185 | + * Generate java code. |
| 184 | * | 186 | * |
| 185 | * @param fileType generated file type | 187 | * @param fileType generated file type |
| 186 | * @param curNode current YANG node | 188 | * @param curNode current YANG node |
| 187 | * @throws IOException when fails to generate java files | 189 | * @throws IOException when fails to generate java files |
| 188 | */ | 190 | */ |
| 191 | + @Override | ||
| 189 | public void generateJavaFile(int fileType, YangNode curNode) | 192 | public void generateJavaFile(int fileType, YangNode curNode) |
| 190 | throws IOException { | 193 | throws IOException { |
| 191 | List<String> imports = new ArrayList<>(); | 194 | List<String> imports = new ArrayList<>(); |
| ... | @@ -199,9 +202,6 @@ public class TempJavaServiceFragmentFiles | ... | @@ -199,9 +202,6 @@ public class TempJavaServiceFragmentFiles |
| 199 | setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX))); | 202 | setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX))); |
| 200 | generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent()); | 203 | generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent()); |
| 201 | 204 | ||
| 202 | - if (isAttributePresent()) { | ||
| 203 | - addImportsToStringAndHasCodeMethods(curNode, imports); | ||
| 204 | - } | ||
| 205 | if (isHasAugmentationExtended(getExtendsList())) { | 205 | if (isHasAugmentationExtended(getExtendsList())) { |
| 206 | addAugmentedInfoImport(curNode, imports, true); | 206 | addAugmentedInfoImport(curNode, imports, true); |
| 207 | addArrayListImport(curNode, imports, true); | 207 | addArrayListImport(curNode, imports, true); |
| ... | @@ -229,21 +229,20 @@ public class TempJavaServiceFragmentFiles | ... | @@ -229,21 +229,20 @@ public class TempJavaServiceFragmentFiles |
| 229 | * @param rpcName name of the rpc function | 229 | * @param rpcName name of the rpc function |
| 230 | * @throws IOException IO operation fail | 230 | * @throws IOException IO operation fail |
| 231 | */ | 231 | */ |
| 232 | - private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, JavaAttributeInfo javaAttributeInfoOfOutput, | 232 | + private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, |
| 233 | - String rpcName) | 233 | + JavaAttributeInfo javaAttributeInfoOfOutput, |
| 234 | - throws IOException { | 234 | + String rpcName) throws IOException { |
| 235 | - String rpcInput = ""; | 235 | + String rpcInput = EMPTY_STRING; |
| 236 | - String rpcOutput = "void"; | 236 | + String rpcOutput = VOID; |
| 237 | if (javaAttributeInfoOfInput != null) { | 237 | if (javaAttributeInfoOfInput != null) { |
| 238 | rpcInput = javaAttributeInfoOfInput.getAttributeName(); | 238 | rpcInput = javaAttributeInfoOfInput.getAttributeName(); |
| 239 | } | 239 | } |
| 240 | if (javaAttributeInfoOfOutput != null) { | 240 | if (javaAttributeInfoOfOutput != null) { |
| 241 | rpcOutput = javaAttributeInfoOfOutput.getAttributeName(); | 241 | rpcOutput = javaAttributeInfoOfOutput.getAttributeName(); |
| 242 | } | 242 | } |
| 243 | - appendToFile(getRpcInterfaceTempFileHandle(), generateJavaDocForRpc(rpcName, rpcInput, rpcOutput) + | 243 | + appendToFile(getRpcInterfaceTempFileHandle(), generateJavaDocForRpc(rpcName, RPC_INPUT_VAR_NAME, rpcOutput) |
| 244 | - getRpcServiceMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE); | 244 | + + getRpcServiceMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE); |
| 245 | - appendToFile(getRpcImplTempFileHandle(), | 245 | + appendToFile(getRpcImplTempFileHandle(), getRpcManagerMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE); |
| 246 | - getRpcManagerMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE); | ||
| 247 | } | 246 | } |
| 248 | 247 | ||
| 249 | /** | 248 | /** |
| ... | @@ -269,12 +268,17 @@ public class TempJavaServiceFragmentFiles | ... | @@ -269,12 +268,17 @@ public class TempJavaServiceFragmentFiles |
| 269 | * and java files. | 268 | * and java files. |
| 270 | * @throws IOException when failed to delete the temporary files | 269 | * @throws IOException when failed to delete the temporary files |
| 271 | */ | 270 | */ |
| 271 | + @Override | ||
| 272 | public void freeTemporaryResources(boolean isErrorOccurred) | 272 | public void freeTemporaryResources(boolean isErrorOccurred) |
| 273 | throws IOException { | 273 | throws IOException { |
| 274 | boolean isError = isErrorOccurred; | 274 | boolean isError = isErrorOccurred; |
| 275 | 275 | ||
| 276 | closeFile(getServiceInterfaceJavaFileHandle(), isError); | 276 | closeFile(getServiceInterfaceJavaFileHandle(), isError); |
| 277 | closeFile(getRpcInterfaceTempFileHandle(), true); | 277 | closeFile(getRpcInterfaceTempFileHandle(), true); |
| 278 | + closeFile(getRpcImplTempFileHandle(), true); | ||
| 279 | + closeFile(getGetterInterfaceTempFileHandle(), true); | ||
| 280 | + closeFile(getSetterInterfaceTempFileHandle(), true); | ||
| 281 | + closeFile(getSetterImplTempFileHandle(), true); | ||
| 278 | 282 | ||
| 279 | super.freeTemporaryResources(isErrorOccurred); | 283 | super.freeTemporaryResources(isErrorOccurred); |
| 280 | 284 | ... | ... |
| ... | @@ -21,6 +21,7 @@ import java.io.IOException; | ... | @@ -21,6 +21,7 @@ import java.io.IOException; |
| 21 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
| 22 | import java.util.List; | 22 | import java.util.List; |
| 23 | 23 | ||
| 24 | +import org.onosproject.yangutils.datamodel.YangDataTypes; | ||
| 24 | import org.onosproject.yangutils.datamodel.YangNode; | 25 | import org.onosproject.yangutils.datamodel.YangNode; |
| 25 | import org.onosproject.yangutils.datamodel.YangType; | 26 | import org.onosproject.yangutils.datamodel.YangType; |
| 26 | import org.onosproject.yangutils.datamodel.YangTypeHolder; | 27 | import org.onosproject.yangutils.datamodel.YangTypeHolder; |
| ... | @@ -33,10 +34,9 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -33,10 +34,9 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
| 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; | 34 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; |
| 34 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; | 35 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; |
| 35 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; | 36 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; |
| 36 | -import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString; | ||
| 37 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile; | 37 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile; |
| 38 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile; | 38 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile; |
| 39 | -import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod; | 39 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 40 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc; | 40 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc; |
| 41 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc; | 41 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc; |
| 42 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; | 42 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
| ... | @@ -60,10 +60,6 @@ public class TempJavaTypeFragmentFiles | ... | @@ -60,10 +60,6 @@ public class TempJavaTypeFragmentFiles |
| 60 | * File name for construction for special type like union, typedef. | 60 | * File name for construction for special type like union, typedef. |
| 61 | */ | 61 | */ |
| 62 | private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType"; | 62 | private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType"; |
| 63 | - /** | ||
| 64 | - * File name for from string method. | ||
| 65 | - */ | ||
| 66 | - private static final String FROM_STRING_METHOD_FILE_NAME = "FromString"; | ||
| 67 | 63 | ||
| 68 | /** | 64 | /** |
| 69 | * File name for typedef class file name suffix. | 65 | * File name for typedef class file name suffix. |
| ... | @@ -86,11 +82,6 @@ public class TempJavaTypeFragmentFiles | ... | @@ -86,11 +82,6 @@ public class TempJavaTypeFragmentFiles |
| 86 | private File constructorForTypeTempFileHandle; | 82 | private File constructorForTypeTempFileHandle; |
| 87 | 83 | ||
| 88 | /** | 84 | /** |
| 89 | - * Temporary file handle for from string method of class. | ||
| 90 | - */ | ||
| 91 | - private File fromStringImplTempFileHandle; | ||
| 92 | - | ||
| 93 | - /** | ||
| 94 | * Java file handle for typedef class file. | 85 | * Java file handle for typedef class file. |
| 95 | */ | 86 | */ |
| 96 | private File typedefClassJavaFileHandle; | 87 | private File typedefClassJavaFileHandle; |
| ... | @@ -118,10 +109,8 @@ public class TempJavaTypeFragmentFiles | ... | @@ -118,10 +109,8 @@ public class TempJavaTypeFragmentFiles |
| 118 | addGeneratedTempFile(CONSTRUCTOR_FOR_TYPE_MASK); | 109 | addGeneratedTempFile(CONSTRUCTOR_FOR_TYPE_MASK); |
| 119 | addGeneratedTempFile(FROM_STRING_IMPL_MASK); | 110 | addGeneratedTempFile(FROM_STRING_IMPL_MASK); |
| 120 | 111 | ||
| 121 | - | ||
| 122 | setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME)); | 112 | setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME)); |
| 123 | setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME)); | 113 | setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME)); |
| 124 | - setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME)); | ||
| 125 | 114 | ||
| 126 | } | 115 | } |
| 127 | 116 | ||
| ... | @@ -146,25 +135,6 @@ public class TempJavaTypeFragmentFiles | ... | @@ -146,25 +135,6 @@ public class TempJavaTypeFragmentFiles |
| 146 | } | 135 | } |
| 147 | 136 | ||
| 148 | /** | 137 | /** |
| 149 | - * Returns from string method's temporary file handle. | ||
| 150 | - * | ||
| 151 | - * @return from string method's temporary file handle | ||
| 152 | - */ | ||
| 153 | - public File getFromStringImplTempFileHandle() { | ||
| 154 | - return fromStringImplTempFileHandle; | ||
| 155 | - } | ||
| 156 | - | ||
| 157 | - /** | ||
| 158 | - * Sets from string method's temporary file handle. | ||
| 159 | - * | ||
| 160 | - * @param fromStringImplTempFileHandle from string method's temporary file | ||
| 161 | - * handle | ||
| 162 | - */ | ||
| 163 | - private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) { | ||
| 164 | - this.fromStringImplTempFileHandle = fromStringImplTempFileHandle; | ||
| 165 | - } | ||
| 166 | - | ||
| 167 | - /** | ||
| 168 | * Returns java file handle for typedef class file. | 138 | * Returns java file handle for typedef class file. |
| 169 | * | 139 | * |
| 170 | * @return java file handle for typedef class file | 140 | * @return java file handle for typedef class file |
| ... | @@ -239,9 +209,14 @@ public class TempJavaTypeFragmentFiles | ... | @@ -239,9 +209,14 @@ public class TempJavaTypeFragmentFiles |
| 239 | } | 209 | } |
| 240 | YangJavaType<?> javaType = (YangJavaType<?>) yangType; | 210 | YangJavaType<?> javaType = (YangJavaType<?>) yangType; |
| 241 | javaType.updateJavaQualifiedInfo(); | 211 | javaType.updateJavaQualifiedInfo(); |
| 212 | + String typeName = javaType.getDataTypeName(); | ||
| 213 | + | ||
| 214 | + if (javaType.getDataType().equals(YangDataTypes.DERIVED)) { | ||
| 215 | + typeName = getCamelCase(typeName, null); | ||
| 216 | + } | ||
| 242 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( | 217 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( |
| 243 | javaType.getJavaQualifiedInfo(), | 218 | javaType.getJavaQualifiedInfo(), |
| 244 | - javaType.getDataTypeName(), javaType, | 219 | + typeName, javaType, |
| 245 | getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()), | 220 | getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()), |
| 246 | false); | 221 | false); |
| 247 | addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo); | 222 | addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo); |
| ... | @@ -269,34 +244,6 @@ public class TempJavaTypeFragmentFiles | ... | @@ -269,34 +244,6 @@ public class TempJavaTypeFragmentFiles |
| 269 | if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { | 244 | if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { |
| 270 | addTypeConstructor(javaAttributeInfo); | 245 | addTypeConstructor(javaAttributeInfo); |
| 271 | } | 246 | } |
| 272 | - | ||
| 273 | - JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(javaAttributeInfo); | ||
| 274 | - /* | ||
| 275 | - * Create a new java attribute info with qualified information of | ||
| 276 | - * wrapper classes. | ||
| 277 | - */ | ||
| 278 | - JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString, | ||
| 279 | - javaAttributeInfo.getAttributeName(), | ||
| 280 | - javaAttributeInfo.getAttributeType(), | ||
| 281 | - getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false); | ||
| 282 | - if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { | ||
| 283 | - addFromStringMethod(javaAttributeInfo, fromStringAttributeInfo); | ||
| 284 | - } | ||
| 285 | - } | ||
| 286 | - | ||
| 287 | - | ||
| 288 | - /** | ||
| 289 | - * Adds from string method for union class. | ||
| 290 | - * | ||
| 291 | - * @param javaAttributeInfo type attribute info | ||
| 292 | - * @param fromStringAttributeInfo from string attribute info | ||
| 293 | - * @throws IOException when fails to append to temporary file | ||
| 294 | - */ | ||
| 295 | - private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo, | ||
| 296 | - JavaAttributeInfo fromStringAttributeInfo) | ||
| 297 | - throws IOException { | ||
| 298 | - appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo, | ||
| 299 | - fromStringAttributeInfo) + NEW_LINE); | ||
| 300 | } | 247 | } |
| 301 | 248 | ||
| 302 | /** | 249 | /** |
| ... | @@ -324,7 +271,6 @@ public class TempJavaTypeFragmentFiles | ... | @@ -324,7 +271,6 @@ public class TempJavaTypeFragmentFiles |
| 324 | + NEW_LINE); | 271 | + NEW_LINE); |
| 325 | } | 272 | } |
| 326 | 273 | ||
| 327 | - | ||
| 328 | /** | 274 | /** |
| 329 | * Removes all temporary file handles. | 275 | * Removes all temporary file handles. |
| 330 | * | 276 | * |
| ... | @@ -333,6 +279,7 @@ public class TempJavaTypeFragmentFiles | ... | @@ -333,6 +279,7 @@ public class TempJavaTypeFragmentFiles |
| 333 | * and java files. | 279 | * and java files. |
| 334 | * @throws IOException when failed to delete the temporary files | 280 | * @throws IOException when failed to delete the temporary files |
| 335 | */ | 281 | */ |
| 282 | + @Override | ||
| 336 | public void freeTemporaryResources(boolean isErrorOccurred) | 283 | public void freeTemporaryResources(boolean isErrorOccurred) |
| 337 | throws IOException { | 284 | throws IOException { |
| 338 | boolean isError = isErrorOccurred; | 285 | boolean isError = isErrorOccurred; |
| ... | @@ -356,6 +303,7 @@ public class TempJavaTypeFragmentFiles | ... | @@ -356,6 +303,7 @@ public class TempJavaTypeFragmentFiles |
| 356 | } | 303 | } |
| 357 | 304 | ||
| 358 | super.freeTemporaryResources(isErrorOccurred); | 305 | super.freeTemporaryResources(isErrorOccurred); |
| 306 | + | ||
| 359 | } | 307 | } |
| 360 | 308 | ||
| 361 | /** | 309 | /** |
| ... | @@ -365,6 +313,7 @@ public class TempJavaTypeFragmentFiles | ... | @@ -365,6 +313,7 @@ public class TempJavaTypeFragmentFiles |
| 365 | * @param curNode current YANG node | 313 | * @param curNode current YANG node |
| 366 | * @throws IOException when fails to generate java files | 314 | * @throws IOException when fails to generate java files |
| 367 | */ | 315 | */ |
| 316 | + @Override | ||
| 368 | public void generateJavaFile(int fileType, YangNode curNode) | 317 | public void generateJavaFile(int fileType, YangNode curNode) |
| 369 | throws IOException { | 318 | throws IOException { |
| 370 | List<String> imports = new ArrayList<>(); | 319 | List<String> imports = new ArrayList<>(); | ... | ... |
| ... | @@ -76,7 +76,6 @@ public class YangJavaEnumeration | ... | @@ -76,7 +76,6 @@ public class YangJavaEnumeration |
| 76 | */ | 76 | */ |
| 77 | @Override | 77 | @Override |
| 78 | public void setJavaFileInfo(JavaFileInfo javaInfo) { | 78 | public void setJavaFileInfo(JavaFileInfo javaInfo) { |
| 79 | - | ||
| 80 | javaFileInfo = javaInfo; | 79 | javaFileInfo = javaInfo; |
| 81 | } | 80 | } |
| 82 | 81 | ||
| ... | @@ -87,7 +86,6 @@ public class YangJavaEnumeration | ... | @@ -87,7 +86,6 @@ public class YangJavaEnumeration |
| 87 | */ | 86 | */ |
| 88 | @Override | 87 | @Override |
| 89 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | 88 | public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { |
| 90 | - | ||
| 91 | return tempFileHandle; | 89 | return tempFileHandle; |
| 92 | } | 90 | } |
| 93 | 91 | ||
| ... | @@ -98,7 +96,6 @@ public class YangJavaEnumeration | ... | @@ -98,7 +96,6 @@ public class YangJavaEnumeration |
| 98 | */ | 96 | */ |
| 99 | @Override | 97 | @Override |
| 100 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | 98 | public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { |
| 101 | - | ||
| 102 | tempFileHandle = fileHandle; | 99 | tempFileHandle = fileHandle; |
| 103 | } | 100 | } |
| 104 | 101 | ... | ... |
| ... | @@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | ... | @@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
| 27 | 27 | ||
| 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
| 29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | 29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
| 30 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir; | ||
| 30 | 31 | ||
| 31 | /** | 32 | /** |
| 32 | * Represents module information extended to support java code generation. | 33 | * Represents module information extended to support java code generation. |
| ... | @@ -118,5 +119,7 @@ public class YangJavaModule | ... | @@ -118,5 +119,7 @@ public class YangJavaModule |
| 118 | public void generateCodeExit() | 119 | public void generateCodeExit() |
| 119 | throws IOException { | 120 | throws IOException { |
| 120 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); | 121 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); |
| 122 | + searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + | ||
| 123 | + getJavaFileInfo().getPackageFilePath()); | ||
| 121 | } | 124 | } |
| 122 | } | 125 | } | ... | ... |
| ... | @@ -28,6 +28,7 @@ import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | ... | @@ -28,6 +28,7 @@ import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
| 28 | 28 | ||
| 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
| 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
| 31 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir; | ||
| 31 | 32 | ||
| 32 | /** | 33 | /** |
| 33 | * Represents sub module information extended to support java code generation. | 34 | * Represents sub module information extended to support java code generation. |
| ... | @@ -133,5 +134,7 @@ public class YangJavaSubModule | ... | @@ -133,5 +134,7 @@ public class YangJavaSubModule |
| 133 | public void generateCodeExit() | 134 | public void generateCodeExit() |
| 134 | throws IOException { | 135 | throws IOException { |
| 135 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); | 136 | getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this); |
| 137 | + searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() + | ||
| 138 | + getJavaFileInfo().getPackageFilePath()); | ||
| 136 | } | 139 | } |
| 137 | } | 140 | } | ... | ... |
| ... | @@ -38,6 +38,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; | ... | @@ -38,6 +38,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; |
| 38 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE; |
| 39 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER; |
| 40 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
| 41 | +import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME; | ||
| 41 | import static org.onosproject.yangutils.utils.UtilConstants.INT; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
| 42 | import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER; | 43 | import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER; |
| 43 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | 44 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; |
| ... | @@ -45,7 +46,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH; | ... | @@ -45,7 +46,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH; |
| 45 | import static org.onosproject.yangutils.utils.UtilConstants.LONG; | 46 | import static org.onosproject.yangutils.utils.UtilConstants.LONG; |
| 46 | import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; | 47 | import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; |
| 47 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; | 48 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; |
| 48 | -import static org.onosproject.yangutils.utils.UtilConstants.OF; | ||
| 49 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE; | 49 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE; |
| 50 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT; | 50 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT; |
| 51 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG; | 51 | import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG; |
| ... | @@ -146,7 +146,7 @@ public final class AttributesJavaDataType { | ... | @@ -146,7 +146,7 @@ public final class AttributesJavaDataType { |
| 146 | case BINARY: | 146 | case BINARY: |
| 147 | //TODO:BINARY | 147 | //TODO:BINARY |
| 148 | case DERIVED: | 148 | case DERIVED: |
| 149 | - return targetDataType + PERIOD + OF; | 149 | + return targetDataType + PERIOD + FROM_STRING_METHOD_NAME; |
| 150 | default: | 150 | default: |
| 151 | throw new TranslatorException("given data type is not supported."); | 151 | throw new TranslatorException("given data type is not supported."); |
| 152 | } | 152 | } |
| ... | @@ -316,8 +316,7 @@ public final class AttributesJavaDataType { | ... | @@ -316,8 +316,7 @@ public final class AttributesJavaDataType { |
| 316 | } else { | 316 | } else { |
| 317 | switch (type) { | 317 | switch (type) { |
| 318 | case UINT64: | 318 | case UINT64: |
| 319 | - //TODO: BIGINTEGER. | 319 | + return JAVA_MATH; |
| 320 | - break; | ||
| 321 | case DECIMAL64: | 320 | case DECIMAL64: |
| 322 | //TODO: DECIMAL64 | 321 | //TODO: DECIMAL64 |
| 323 | break; | 322 | break; | ... | ... |
| ... | @@ -74,7 +74,7 @@ public final class ClassDefinitionGenerator { | ... | @@ -74,7 +74,7 @@ public final class ClassDefinitionGenerator { |
| 74 | if ((genFileTypes & INTERFACE_MASK) != 0) { | 74 | if ((genFileTypes & INTERFACE_MASK) != 0) { |
| 75 | return getInterfaceDefinition(yangName); | 75 | return getInterfaceDefinition(yangName); |
| 76 | } else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) { | 76 | } else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) { |
| 77 | - return getBuilderClassDefinition(yangName, genFileTypes); | 77 | + return getBuilderClassDefinition(yangName); |
| 78 | } else if ((genFileTypes & IMPL_CLASS_MASK) != 0) { | 78 | } else if ((genFileTypes & IMPL_CLASS_MASK) != 0) { |
| 79 | return getImplClassDefinition(yangName); | 79 | return getImplClassDefinition(yangName); |
| 80 | } else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) { | 80 | } else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) { |
| ... | @@ -142,15 +142,10 @@ public final class ClassDefinitionGenerator { | ... | @@ -142,15 +142,10 @@ public final class ClassDefinitionGenerator { |
| 142 | * @param genFileTypes | 142 | * @param genFileTypes |
| 143 | * @return definition | 143 | * @return definition |
| 144 | */ | 144 | */ |
| 145 | - private static String getBuilderClassDefinition(String yangName, int genFileTypes) { | 145 | + private static String getBuilderClassDefinition(String yangName) { |
| 146 | - if ((genFileTypes & GENERATE_SERVICE_AND_MANAGER) != 0) { | ||
| 147 | - return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName + | ||
| 148 | - SERVICE + PERIOD + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | ||
| 149 | - } else { | ||
| 150 | return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD | 146 | return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD |
| 151 | + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 147 | + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 152 | } | 148 | } |
| 153 | - } | ||
| 154 | 149 | ||
| 155 | /** | 150 | /** |
| 156 | * Returns impl file class definition. | 151 | * Returns impl file class definition. |
| ... | @@ -180,7 +175,11 @@ public final class ClassDefinitionGenerator { | ... | @@ -180,7 +175,11 @@ public final class ClassDefinitionGenerator { |
| 180 | * @return definition | 175 | * @return definition |
| 181 | */ | 176 | */ |
| 182 | private static String getRpcInterfaceDefinition(String yangName) { | 177 | private static String getRpcInterfaceDefinition(String yangName) { |
| 183 | - return INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 178 | + if (yangName.contains(SERVICE)) { |
| 179 | + return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | ||
| 180 | + } | ||
| 181 | + return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName + SERVICE | ||
| 182 | + + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | ||
| 184 | } | 183 | } |
| 185 | 184 | ||
| 186 | /** | 185 | /** |
| ... | @@ -195,7 +194,7 @@ public final class ClassDefinitionGenerator { | ... | @@ -195,7 +194,7 @@ public final class ClassDefinitionGenerator { |
| 195 | if (classDef.length() < 5) { | 194 | if (classDef.length() < 5) { |
| 196 | throw new RuntimeException("Event class name is error"); | 195 | throw new RuntimeException("Event class name is error"); |
| 197 | } | 196 | } |
| 198 | - classDef = classDef.substring(0, (classDef.length() - 5)); | 197 | + classDef = classDef.substring(0, classDef.length() - 5); |
| 199 | classDef = classDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 198 | classDef = classDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 200 | 199 | ||
| 201 | return classDef; | 200 | return classDef; |
| ... | @@ -213,7 +212,7 @@ public final class ClassDefinitionGenerator { | ... | @@ -213,7 +212,7 @@ public final class ClassDefinitionGenerator { |
| 213 | if (intfDef.length() < 8) { | 212 | if (intfDef.length() < 8) { |
| 214 | throw new RuntimeException("Event listener interface name is error"); | 213 | throw new RuntimeException("Event listener interface name is error"); |
| 215 | } | 214 | } |
| 216 | - intfDef = intfDef.substring(0, (intfDef.length() - 8)); | 215 | + intfDef = intfDef.substring(0, intfDef.length() - 8); |
| 217 | intfDef = intfDef + "Event>" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 216 | intfDef = intfDef + "Event>" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 218 | 217 | ||
| 219 | return intfDef; | 218 | return intfDef; | ... | ... |
| ... | @@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava.utils; | ... | @@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava.utils; |
| 19 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | 19 | import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
| 20 | 20 | ||
| 21 | import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; | 21 | import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; |
| 22 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | ||
| 23 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute; | 22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute; |
| 24 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 23 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
| 25 | import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; | 24 | import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; |
| ... | @@ -87,11 +86,6 @@ public final class JavaCodeSnippetGen { | ... | @@ -87,11 +86,6 @@ public final class JavaCodeSnippetGen { |
| 87 | * @return corresponding textual java code information | 86 | * @return corresponding textual java code information |
| 88 | */ | 87 | */ |
| 89 | public static String getJavaClassDefStart(int genFileTypes, String yangName) { | 88 | public static String getJavaClassDefStart(int genFileTypes, String yangName) { |
| 90 | - | ||
| 91 | - /* | ||
| 92 | - * get the camel case name for java class / interface. | ||
| 93 | - */ | ||
| 94 | - yangName = getCamelCase(yangName, null); | ||
| 95 | return generateClassDefinition(genFileTypes, yangName); | 89 | return generateClassDefinition(genFileTypes, yangName); |
| 96 | } | 90 | } |
| 97 | 91 | ||
| ... | @@ -168,8 +162,9 @@ public final class JavaCodeSnippetGen { | ... | @@ -168,8 +162,9 @@ public final class JavaCodeSnippetGen { |
| 168 | * @return string for enum's attribute | 162 | * @return string for enum's attribute |
| 169 | */ | 163 | */ |
| 170 | public static String generateEnumAttributeString(String name, int value) { | 164 | public static String generateEnumAttributeString(String name, int value) { |
| 171 | - return getJavaDoc(ENUM_ATTRIBUTE, name, false) + FOUR_SPACE_INDENTATION + getEnumJavaAttribute(name) | 165 | + return getJavaDoc(ENUM_ATTRIBUTE, name, false) + FOUR_SPACE_INDENTATION |
| 172 | - + OPEN_PARENTHESIS + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE; | 166 | + + getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS |
| 167 | + + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE; | ||
| 173 | } | 168 | } |
| 174 | 169 | ||
| 175 | } | 170 | } | ... | ... |
| ... | @@ -25,6 +25,7 @@ import org.onosproject.yangutils.datamodel.YangNode; | ... | @@ -25,6 +25,7 @@ import org.onosproject.yangutils.datamodel.YangNode; |
| 25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
| 26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | 26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
| 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; | 27 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; |
| 28 | +import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; | ||
| 28 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; | 29 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; |
| 29 | 30 | ||
| 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| ... | @@ -62,6 +63,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator | ... | @@ -62,6 +63,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator |
| 62 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl; | 63 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl; |
| 63 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; | 64 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; |
| 64 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstrcutor; | 65 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstrcutor; |
| 66 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfMethod; | ||
| 65 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; | 67 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; |
| 66 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; | 68 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; |
| 67 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose; | 69 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose; |
| ... | @@ -84,7 +86,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; | ... | @@ -84,7 +86,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; |
| 84 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 86 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
| 85 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | 87 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
| 86 | import static org.onosproject.yangutils.utils.UtilConstants.INT; | 88 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
| 87 | -import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; | ||
| 88 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 89 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
| 89 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | 90 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
| 90 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | 91 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
| ... | @@ -164,7 +165,8 @@ public final class JavaFileGenerator { | ... | @@ -164,7 +165,8 @@ public final class JavaFileGenerator { |
| 164 | * @return interface file | 165 | * @return interface file |
| 165 | * @throws IOException when fails to write in file | 166 | * @throws IOException when fails to write in file |
| 166 | */ | 167 | */ |
| 167 | - public static File generateInterfaceFile(File file, List<String> imports, YangNode curNode, boolean isAttrPresent) | 168 | + public static File generateInterfaceFile(File file, List<String> imports, YangNode curNode, |
| 169 | + boolean isAttrPresent) | ||
| 168 | throws IOException { | 170 | throws IOException { |
| 169 | 171 | ||
| 170 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 172 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
| ... | @@ -311,7 +313,8 @@ public final class JavaFileGenerator { | ... | @@ -311,7 +313,8 @@ public final class JavaFileGenerator { |
| 311 | /** | 313 | /** |
| 312 | * Add default constructor and build method impl. | 314 | * Add default constructor and build method impl. |
| 313 | */ | 315 | */ |
| 314 | - methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().addBuildMethodImpl()); | 316 | + methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 317 | + .addBuildMethodImpl()); | ||
| 315 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 318 | methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 316 | .addDefaultConstructor(PUBLIC, BUILDER)); | 319 | .addDefaultConstructor(PUBLIC, BUILDER)); |
| 317 | 320 | ||
| ... | @@ -340,43 +343,46 @@ public final class JavaFileGenerator { | ... | @@ -340,43 +343,46 @@ public final class JavaFileGenerator { |
| 340 | 343 | ||
| 341 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 344 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
| 342 | 345 | ||
| 343 | - String className = getCaptialCase(javaFileInfo.getJavaName()) + MANAGER; | 346 | + String className = getCaptialCase(javaFileInfo.getJavaName()); |
| 344 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 347 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
| 345 | 348 | ||
| 346 | initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path); | 349 | initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path); |
| 347 | 350 | ||
| 348 | List<String> methods = new ArrayList<>(); | 351 | List<String> methods = new ArrayList<>(); |
| 349 | 352 | ||
| 350 | - if (isAttrPresent) { | ||
| 351 | - | ||
| 352 | try { | 353 | try { |
| 354 | + if (isAttrPresent) { | ||
| 353 | /** | 355 | /** |
| 354 | * Getter methods. | 356 | * Getter methods. |
| 355 | */ | 357 | */ |
| 356 | - methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, | 358 | + methods.add( |
| 357 | - ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 359 | + getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, |
| 358 | - .getServiceTempFiles())); | 360 | + ((TempJavaCodeFragmentFilesContainer) curNode) |
| 361 | + .getTempJavaCodeFragmentFiles().getServiceTempFiles())); | ||
| 359 | /** | 362 | /** |
| 360 | * Setter methods. | 363 | * Setter methods. |
| 361 | */ | 364 | */ |
| 362 | - methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK, | 365 | + methods.add( |
| 363 | - ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 366 | + getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK, |
| 364 | - .getServiceTempFiles()) + | 367 | + ((TempJavaCodeFragmentFilesContainer) curNode) |
| 365 | - NEW_LINE); | 368 | + .getTempJavaCodeFragmentFiles().getServiceTempFiles()) |
| 369 | + + NEW_LINE); | ||
| 366 | 370 | ||
| 371 | + } | ||
| 372 | + if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) { | ||
| 367 | JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; | 373 | JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; |
| 368 | /** | 374 | /** |
| 369 | * Rpc methods | 375 | * Rpc methods |
| 370 | */ | 376 | */ |
| 371 | - methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles() | 377 | + methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK, |
| 372 | - .getServiceTempFiles())); | 378 | + javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles())); |
| 379 | + } | ||
| 380 | + insertDataIntoJavaFile(file, NEW_LINE); | ||
| 381 | + | ||
| 373 | } catch (IOException e) { | 382 | } catch (IOException e) { |
| 374 | throw new IOException("No data found in temporary java code fragment files for " + className | 383 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 375 | + " while manager class file generation"); | 384 | + " while manager class file generation"); |
| 376 | } | 385 | } |
| 377 | - } else { | ||
| 378 | - insertDataIntoJavaFile(file, NEW_LINE); | ||
| 379 | - } | ||
| 380 | 386 | ||
| 381 | /** | 387 | /** |
| 382 | * Add methods in builder class. | 388 | * Add methods in builder class. |
| ... | @@ -746,16 +752,34 @@ public final class JavaFileGenerator { | ... | @@ -746,16 +752,34 @@ public final class JavaFileGenerator { |
| 746 | /** | 752 | /** |
| 747 | * Add a constructor for enum. | 753 | * Add a constructor for enum. |
| 748 | */ | 754 | */ |
| 749 | - insertDataIntoJavaFile(file, | 755 | + insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, getSmallCase(className), false) |
| 750 | - getJavaDoc(TYPE_CONSTRUCTOR, getSmallCase(className), false) + getEnumsConstrcutor(className) | 756 | + + getEnumsConstrcutor(className) + NEW_LINE); |
| 757 | + | ||
| 758 | + TempJavaEnumerationFragmentFiles enumFragFiles = | ||
| 759 | + ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | ||
| 760 | + .getEnumerationTempFiles(); | ||
| 761 | + insertDataIntoJavaFile(file, getEnumsOfMethod(className, | ||
| 762 | + enumFragFiles.getJavaAttributeForEnum(), | ||
| 763 | + enumFragFiles.getEnumSetJavaMap(), | ||
| 764 | + enumFragFiles.getEnumStringList()) | ||
| 751 | + NEW_LINE); | 765 | + NEW_LINE); |
| 752 | 766 | ||
| 753 | /** | 767 | /** |
| 754 | * Add a getter method for enum. | 768 | * Add a getter method for enum. |
| 755 | */ | 769 | */ |
| 756 | - insertDataIntoJavaFile(file, | 770 | + insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, getSmallCase(className), false) |
| 757 | - getJavaDoc(GETTER_METHOD, getSmallCase(className), false) | 771 | + + getGetter(INT, getSmallCase(className), GENERATE_ENUM_CLASS) + NEW_LINE); |
| 758 | - + getGetter(INT, getSmallCase(className), GENERATE_SERVICE_AND_MANAGER) + NEW_LINE); | 772 | + |
| 773 | + try { | ||
| 774 | + insertDataIntoJavaFile(file, getFromStringMethodSignature(className) | ||
| 775 | + + getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, | ||
| 776 | + ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | ||
| 777 | + .getEnumerationTempFiles()) | ||
| 778 | + + getFromStringMethodClose()); | ||
| 779 | + } catch (IOException e) { | ||
| 780 | + throw new IOException("No data found in temporary java code fragment files for " + className | ||
| 781 | + + " while enum class file generation"); | ||
| 782 | + } | ||
| 759 | 783 | ||
| 760 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | 784 | insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); |
| 761 | 785 | ||
| ... | @@ -785,33 +809,30 @@ public final class JavaFileGenerator { | ... | @@ -785,33 +809,30 @@ public final class JavaFileGenerator { |
| 785 | 809 | ||
| 786 | List<String> methods = new ArrayList<>(); | 810 | List<String> methods = new ArrayList<>(); |
| 787 | 811 | ||
| 788 | - | ||
| 789 | try { | 812 | try { |
| 790 | if (isAttributePresent) { | 813 | if (isAttributePresent) { |
| 791 | 814 | ||
| 792 | /** | 815 | /** |
| 793 | * Getter methods. | 816 | * Getter methods. |
| 794 | */ | 817 | */ |
| 795 | - methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, | 818 | + methods.add(getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, |
| 796 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 819 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 797 | .getServiceTempFiles())); | 820 | .getServiceTempFiles())); |
| 798 | /** | 821 | /** |
| 799 | * Setter methods. | 822 | * Setter methods. |
| 800 | */ | 823 | */ |
| 801 | - methods.add(NEW_LINE); | 824 | + methods.add(getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK, |
| 802 | - methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK, | ||
| 803 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() | 825 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 804 | .getServiceTempFiles())); | 826 | .getServiceTempFiles())); |
| 805 | } | 827 | } |
| 806 | - | 828 | + if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) { |
| 807 | - | ||
| 808 | JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; | 829 | JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; |
| 809 | /** | 830 | /** |
| 810 | * Rpc methods | 831 | * Rpc methods |
| 811 | */ | 832 | */ |
| 812 | - methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK, javaGeninfo.getTempJavaCodeFragmentFiles() | 833 | + methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK, |
| 813 | - .getServiceTempFiles())); | 834 | + javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles())); |
| 814 | - | 835 | + } |
| 815 | } catch (IOException e) { | 836 | } catch (IOException e) { |
| 816 | throw new IOException("No data found in temporary java code fragment files for " + className | 837 | throw new IOException("No data found in temporary java code fragment files for " + className |
| 817 | + " while rpc class file generation"); | 838 | + " while rpc class file generation"); | ... | ... |
| ... | @@ -23,6 +23,7 @@ import java.util.List; | ... | @@ -23,6 +23,7 @@ import java.util.List; |
| 23 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 23 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
| 24 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 24 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
| 25 | import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles; | 25 | import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles; |
| 26 | +import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; | ||
| 26 | import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles; | 27 | import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles; |
| 27 | import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles; | 28 | import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles; |
| 28 | import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles; | 29 | import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles; |
| ... | @@ -39,6 +40,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -39,6 +40,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
| 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
| 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
| 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
| 43 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; | ||
| 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; | 44 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
| 43 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; | 45 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
| 44 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; | 46 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; |
| ... | @@ -58,13 +60,16 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy | ... | @@ -58,13 +60,16 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy |
| 58 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 60 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
| 59 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 61 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
| 60 | import static org.onosproject.yangutils.utils.UtilConstants.INT; | 62 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
| 63 | +import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; | ||
| 61 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 64 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
| 62 | import static org.onosproject.yangutils.utils.UtilConstants.ORG; | 65 | import static org.onosproject.yangutils.utils.UtilConstants.ORG; |
| 63 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; | 66 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; |
| 64 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | 67 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
| 65 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 68 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
| 69 | +import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; | ||
| 66 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 70 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
| 67 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 71 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
| 72 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
| 68 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; | 73 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; |
| 69 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; | 74 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; |
| 70 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS; | 75 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS; |
| ... | @@ -73,7 +78,7 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVE | ... | @@ -73,7 +78,7 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVE |
| 73 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; | 78 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; |
| 74 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; | 79 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; |
| 75 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE; | 80 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE; |
| 76 | -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | 81 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_MANAGER; |
| 77 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | 82 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
| 78 | 83 | ||
| 79 | /** | 84 | /** |
| ... | @@ -105,7 +110,6 @@ public final class JavaFileGeneratorUtils { | ... | @@ -105,7 +110,6 @@ public final class JavaFileGeneratorUtils { |
| 105 | * Returns data stored in temporary files. | 110 | * Returns data stored in temporary files. |
| 106 | * | 111 | * |
| 107 | * @param generatedTempFiles temporary file types | 112 | * @param generatedTempFiles temporary file types |
| 108 | - * @param generatedTempFiles temporary file types | ||
| 109 | * @param tempJavaFragmentFiles temp java fragment files | 113 | * @param tempJavaFragmentFiles temp java fragment files |
| 110 | * @return data stored in temporary files | 114 | * @return data stored in temporary files |
| 111 | * @throws IOException when failed to get the data from temporary file handle | 115 | * @throws IOException when failed to get the data from temporary file handle |
| ... | @@ -130,9 +134,10 @@ public final class JavaFileGeneratorUtils { | ... | @@ -130,9 +134,10 @@ public final class JavaFileGeneratorUtils { |
| 130 | if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) { | 134 | if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) { |
| 131 | serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles; | 135 | serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles; |
| 132 | } | 136 | } |
| 133 | - | 137 | + if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { |
| 134 | - | 138 | + return tempJavaFragmentFiles |
| 135 | - if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) { | 139 | + .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle()); |
| 140 | + } else if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) { | ||
| 136 | return tempJavaFragmentFiles | 141 | return tempJavaFragmentFiles |
| 137 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterInterfaceTempFileHandle()); | 142 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterInterfaceTempFileHandle()); |
| 138 | } else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) { | 143 | } else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) { |
| ... | @@ -172,14 +177,16 @@ public final class JavaFileGeneratorUtils { | ... | @@ -172,14 +177,16 @@ public final class JavaFileGeneratorUtils { |
| 172 | return typeFragmentFiles | 177 | return typeFragmentFiles |
| 173 | .getTemporaryDataFromFileHandle(typeFragmentFiles.getConstructorForTypeTempFileHandle()); | 178 | .getTemporaryDataFromFileHandle(typeFragmentFiles.getConstructorForTypeTempFileHandle()); |
| 174 | } else if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) { | 179 | } else if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) { |
| 175 | - if (typeFragmentFiles == null) { | ||
| 176 | - throw new TranslatorException("Required from string info is missing."); | ||
| 177 | - } | ||
| 178 | - return typeFragmentFiles | ||
| 179 | - .getTemporaryDataFromFileHandle(typeFragmentFiles.getFromStringImplTempFileHandle()); | ||
| 180 | - } else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) { | ||
| 181 | return tempJavaFragmentFiles | 180 | return tempJavaFragmentFiles |
| 182 | - .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getEnumClassTempFileHandle()); | 181 | + .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getFromStringImplTempFileHandle()); |
| 182 | + } else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) { | ||
| 183 | + if (!(tempJavaFragmentFiles instanceof TempJavaEnumerationFragmentFiles)) { | ||
| 184 | + throw new TranslatorException("Required enum info is missing."); | ||
| 185 | + } | ||
| 186 | + TempJavaEnumerationFragmentFiles enumFragmentFiles = | ||
| 187 | + (TempJavaEnumerationFragmentFiles) tempJavaFragmentFiles; | ||
| 188 | + return enumFragmentFiles | ||
| 189 | + .getTemporaryDataFromFileHandle(enumFragmentFiles.getEnumClassTempFileHandle()); | ||
| 183 | } else if ((generatedTempFiles & RPC_INTERFACE_MASK) != 0) { | 190 | } else if ((generatedTempFiles & RPC_INTERFACE_MASK) != 0) { |
| 184 | if (serviceFragmentFiles == null) { | 191 | if (serviceFragmentFiles == null) { |
| 185 | throw new TranslatorException("Required rpc interface info is missing."); | 192 | throw new TranslatorException("Required rpc interface info is missing."); |
| ... | @@ -328,7 +335,15 @@ public final class JavaFileGeneratorUtils { | ... | @@ -328,7 +335,15 @@ public final class JavaFileGeneratorUtils { |
| 328 | */ | 335 | */ |
| 329 | private static void write(File file, String fileName, int genType, JavaDocType javaDocType) | 336 | private static void write(File file, String fileName, int genType, JavaDocType javaDocType) |
| 330 | throws IOException { | 337 | throws IOException { |
| 338 | + if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) { | ||
| 339 | + if (!fileName.contains(SERVICE)) { | ||
| 340 | + insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false)); | ||
| 341 | + } else { | ||
| 331 | insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); | 342 | insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); |
| 343 | + } | ||
| 344 | + } else { | ||
| 345 | + insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); | ||
| 346 | + } | ||
| 332 | insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName)); | 347 | insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName)); |
| 333 | } | 348 | } |
| 334 | 349 | ... | ... |
| ... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +16,9 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | 18 | ||
| 19 | +import java.util.List; | ||
| 20 | +import java.util.Map; | ||
| 21 | + | ||
| 19 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; | 22 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
| 20 | import org.onosproject.yangutils.utils.io.impl.JavaDocGen; | 23 | import org.onosproject.yangutils.utils.io.impl.JavaDocGen; |
| 21 | 24 | ||
| ... | @@ -31,12 +34,15 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | ... | @@ -31,12 +34,15 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
| 31 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; |
| 32 | import static org.onosproject.yangutils.utils.UtilConstants.BUILD; | 35 | import static org.onosproject.yangutils.utils.UtilConstants.BUILD; |
| 33 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 37 | +import static org.onosproject.yangutils.utils.UtilConstants.CASE; | ||
| 34 | import static org.onosproject.yangutils.utils.UtilConstants.CATCH; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.CATCH; |
| 35 | import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING; |
| 36 | import static org.onosproject.yangutils.utils.UtilConstants.CLEAR; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.CLEAR; |
| 37 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
| 38 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
| 43 | +import static org.onosproject.yangutils.utils.UtilConstants.COLAN; | ||
| 39 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | 44 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
| 45 | +import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; | ||
| 40 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | 46 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; |
| 41 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | 47 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; |
| 42 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; | 48 | import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION; |
| ... | @@ -82,6 +88,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ... | @@ -82,6 +88,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
| 82 | import static org.onosproject.yangutils.utils.UtilConstants.STATIC; | 88 | import static org.onosproject.yangutils.utils.UtilConstants.STATIC; |
| 83 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | 89 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
| 84 | import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; | 90 | import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; |
| 91 | +import static org.onosproject.yangutils.utils.UtilConstants.SWITCH; | ||
| 85 | import static org.onosproject.yangutils.utils.UtilConstants.THIS; | 92 | import static org.onosproject.yangutils.utils.UtilConstants.THIS; |
| 86 | import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL; | 93 | import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL; |
| 87 | import static org.onosproject.yangutils.utils.UtilConstants.TO; | 94 | import static org.onosproject.yangutils.utils.UtilConstants.TO; |
| ... | @@ -494,10 +501,11 @@ public final class MethodsGenerator { | ... | @@ -494,10 +501,11 @@ public final class MethodsGenerator { |
| 494 | 501 | ||
| 495 | rpcName = getSmallCase(getCamelCase(rpcName, null)); | 502 | rpcName = getSmallCase(getCamelCase(rpcName, null)); |
| 496 | inputName = getCaptialCase(inputName); | 503 | inputName = getCaptialCase(inputName); |
| 504 | + if (!outputName.equals(VOID)) { | ||
| 497 | outputName = getCaptialCase(outputName); | 505 | outputName = getCaptialCase(outputName); |
| 498 | - | 506 | + } |
| 499 | - return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName + OPEN_PARENTHESIS | 507 | + return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName + SPACE |
| 500 | - + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SEMI_COLAN; | 508 | + + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SEMI_COLAN; |
| 501 | } | 509 | } |
| 502 | 510 | ||
| 503 | /** | 511 | /** |
| ... | @@ -512,12 +520,14 @@ public final class MethodsGenerator { | ... | @@ -512,12 +520,14 @@ public final class MethodsGenerator { |
| 512 | 520 | ||
| 513 | rpcName = getSmallCase(getCamelCase(rpcName, null)); | 521 | rpcName = getSmallCase(getCamelCase(rpcName, null)); |
| 514 | inputName = getCaptialCase(inputName); | 522 | inputName = getCaptialCase(inputName); |
| 523 | + if (!outputName.equals(VOID)) { | ||
| 515 | outputName = getCaptialCase(outputName); | 524 | outputName = getCaptialCase(outputName); |
| 525 | + } | ||
| 516 | 526 | ||
| 517 | - String method = getOverRideString() + | 527 | + String method = |
| 518 | - FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName + OPEN_PARENTHESIS | 528 | + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName |
| 519 | - + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET | 529 | + + OPEN_PARENTHESIS + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE |
| 520 | - + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE; | 530 | + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE; |
| 521 | if (!outputName.contentEquals(VOID)) { | 531 | if (!outputName.contentEquals(VOID)) { |
| 522 | method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE; | 532 | method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE; |
| 523 | } | 533 | } |
| ... | @@ -601,7 +611,7 @@ public final class MethodsGenerator { | ... | @@ -601,7 +611,7 @@ public final class MethodsGenerator { |
| 601 | * @return from string method's open string | 611 | * @return from string method's open string |
| 602 | */ | 612 | */ |
| 603 | public static String getFromStringMethodSignature(String className) { | 613 | public static String getFromStringMethodSignature(String className) { |
| 604 | - return getJavaDoc(FROM_METHOD, className, false) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE | 614 | + return getJavaDoc(FROM_METHOD, className, false) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE |
| 605 | + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE | 615 | + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE |
| 606 | + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 616 | + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
| 607 | } | 617 | } |
| ... | @@ -677,7 +687,6 @@ public final class MethodsGenerator { | ... | @@ -677,7 +687,6 @@ public final class MethodsGenerator { |
| 677 | + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS; | 687 | + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS; |
| 678 | } | 688 | } |
| 679 | 689 | ||
| 680 | - | ||
| 681 | /** | 690 | /** |
| 682 | * Returns hash code method open strings. | 691 | * Returns hash code method open strings. |
| 683 | * | 692 | * |
| ... | @@ -916,4 +925,38 @@ public final class MethodsGenerator { | ... | @@ -916,4 +925,38 @@ public final class MethodsGenerator { |
| 916 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL | 925 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL |
| 917 | + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | 926 | + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
| 918 | } | 927 | } |
| 928 | + | ||
| 929 | + /** | ||
| 930 | + * Returns of method for enum class. | ||
| 931 | + * | ||
| 932 | + * @param className class name | ||
| 933 | + * @param attr java attribute | ||
| 934 | + * @param enumMap enum's sets map | ||
| 935 | + * @param enumList enum's sets list | ||
| 936 | + * @return of method | ||
| 937 | + */ | ||
| 938 | + public static String getEnumsOfMethod(String className, JavaAttributeInfo attr, | ||
| 939 | + Map<String, Integer> enumMap, List<String> enumList) { | ||
| 940 | + String attrType = getReturnType(attr); | ||
| 941 | + String attrName = getSmallCase(attr.getAttributeName()); | ||
| 942 | + | ||
| 943 | + String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + className + SPACE + OF | ||
| 944 | + + OPEN_PARENTHESIS | ||
| 945 | + + attrType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE | ||
| 946 | + + EIGHT_SPACE_INDENTATION + SWITCH + SPACE + OPEN_PARENTHESIS + VALUE | ||
| 947 | + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | ||
| 948 | + int value = 0; | ||
| 949 | + for (String str : enumList) { | ||
| 950 | + | ||
| 951 | + value = enumMap.get(str); | ||
| 952 | + method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLAN + NEW_LINE | ||
| 953 | + + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + className + PERIOD | ||
| 954 | + + str + SEMI_COLAN + NEW_LINE; | ||
| 955 | + } | ||
| 956 | + method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLAN + NEW_LINE + SIXTEEN_SPACE_INDENTATION | ||
| 957 | + + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET | ||
| 958 | + + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | ||
| 959 | + | ||
| 960 | + return getJavaDoc(OF_METHOD, className + " for type " + attrName, false) + method; | ||
| 961 | + } | ||
| 919 | } | 962 | } | ... | ... |
| ... | @@ -21,7 +21,11 @@ import java.io.IOException; | ... | @@ -21,7 +21,11 @@ import java.io.IOException; |
| 21 | import java.util.List; | 21 | import java.util.List; |
| 22 | 22 | ||
| 23 | import org.onosproject.yangutils.datamodel.YangNode; | 23 | import org.onosproject.yangutils.datamodel.YangNode; |
| 24 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | ||
| 24 | import org.onosproject.yangutils.translator.tojava.JavaImportDataContainer; | 25 | import org.onosproject.yangutils.translator.tojava.JavaImportDataContainer; |
| 26 | +import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ||
| 27 | + | ||
| 28 | +import static java.util.Collections.sort; | ||
| 25 | 29 | ||
| 26 | import static org.onosproject.yangutils.translator.tojava.JavaImportData.getAugmentedInfoImport; | 30 | import static org.onosproject.yangutils.translator.tojava.JavaImportData.getAugmentedInfoImport; |
| 27 | import static org.onosproject.yangutils.translator.tojava.JavaImportData.getHasAugmentationImport; | 31 | import static org.onosproject.yangutils.translator.tojava.JavaImportData.getHasAugmentationImport; |
| ... | @@ -31,8 +35,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | ... | @@ -31,8 +35,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
| 31 | import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; | 35 | import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; |
| 32 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; | 36 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; |
| 33 | 37 | ||
| 34 | -import static java.util.Collections.sort; | ||
| 35 | - | ||
| 36 | /** | 38 | /** |
| 37 | * Represents utilities for temporary java code fragments. | 39 | * Represents utilities for temporary java code fragments. |
| 38 | */ | 40 | */ |
| ... | @@ -52,7 +54,8 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -52,7 +54,8 @@ public final class TempJavaCodeFragmentFilesUtils { |
| 52 | * @param operation add or delete import | 54 | * @param operation add or delete import |
| 53 | * @return import for HasAugmentation class | 55 | * @return import for HasAugmentation class |
| 54 | */ | 56 | */ |
| 55 | - public static List<String> addHasAugmentationImport(YangNode curNode, List<String> imports, boolean operation) { | 57 | + public static List<String> addHasAugmentationImport(YangNode curNode, List<String> imports, |
| 58 | + boolean operation) { | ||
| 56 | if (curNode instanceof JavaImportDataContainer) { | 59 | if (curNode instanceof JavaImportDataContainer) { |
| 57 | String thisImport = getHasAugmentationImport(); | 60 | String thisImport = getHasAugmentationImport(); |
| 58 | performOperationOnImports(imports, thisImport, operation); | 61 | performOperationOnImports(imports, thisImport, operation); |
| ... | @@ -109,13 +112,14 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -109,13 +112,14 @@ public final class TempJavaCodeFragmentFilesUtils { |
| 109 | * @param operation add or remove | 112 | * @param operation add or remove |
| 110 | * @return import list | 113 | * @return import list |
| 111 | */ | 114 | */ |
| 112 | - private static List<String> performOperationOnImports(List<String> imports, String curImport, boolean operation) { | 115 | + private static List<String> performOperationOnImports(List<String> imports, String curImport, |
| 116 | + boolean operation) { | ||
| 113 | if (operation) { | 117 | if (operation) { |
| 114 | imports.add(curImport); | 118 | imports.add(curImport); |
| 115 | } else { | 119 | } else { |
| 116 | imports.remove(curImport); | 120 | imports.remove(curImport); |
| 117 | } | 121 | } |
| 118 | - sort(imports); | 122 | + sortImports(imports); |
| 119 | return imports; | 123 | return imports; |
| 120 | } | 124 | } |
| 121 | 125 | ||
| ... | @@ -142,7 +146,7 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -142,7 +146,7 @@ public final class TempJavaCodeFragmentFilesUtils { |
| 142 | * @return true or false | 146 | * @return true or false |
| 143 | */ | 147 | */ |
| 144 | public static boolean isHasAugmentationExtended(List<String> extendsList) { | 148 | public static boolean isHasAugmentationExtended(List<String> extendsList) { |
| 145 | - return (extendsList != null && extendsList.contains(HAS_AUGMENTATION)); | 149 | + return extendsList != null && extendsList.contains(HAS_AUGMENTATION); |
| 146 | } | 150 | } |
| 147 | 151 | ||
| 148 | /** | 152 | /** |
| ... | @@ -152,7 +156,7 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -152,7 +156,7 @@ public final class TempJavaCodeFragmentFilesUtils { |
| 152 | * @return true or false | 156 | * @return true or false |
| 153 | */ | 157 | */ |
| 154 | public static boolean isAugmentedInfoExtended(List<String> extendsList) { | 158 | public static boolean isAugmentedInfoExtended(List<String> extendsList) { |
| 155 | - return (extendsList != null && extendsList.contains(AUGMENTED_INFO)); | 159 | + return extendsList != null && extendsList.contains(AUGMENTED_INFO); |
| 156 | } | 160 | } |
| 157 | 161 | ||
| 158 | /** | 162 | /** |
| ... | @@ -172,4 +176,37 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -172,4 +176,37 @@ public final class TempJavaCodeFragmentFilesUtils { |
| 172 | } | 176 | } |
| 173 | } | 177 | } |
| 174 | } | 178 | } |
| 179 | + | ||
| 180 | + /** | ||
| 181 | + * Detects collision between parent and child node which have same name. | ||
| 182 | + * When parent and child node both have the same name in that case child node should be used with | ||
| 183 | + * qualified name. | ||
| 184 | + * | ||
| 185 | + * @param curNode current YANG node | ||
| 186 | + * @param qualifiedTypeInfo current node's qualified info | ||
| 187 | + * @return true if collision is detected | ||
| 188 | + */ | ||
| 189 | + public static boolean detectCollisionBwParentAndChildForImport(YangNode curNode, | ||
| 190 | + JavaQualifiedTypeInfo qualifiedTypeInfo) { | ||
| 191 | + | ||
| 192 | + YangNode parent = curNode.getParent(); | ||
| 193 | + String parentsClassInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName(); | ||
| 194 | + String childsClassInfo = qualifiedTypeInfo.getClassInfo(); | ||
| 195 | + if (childsClassInfo.equals(parentsClassInfo)) { | ||
| 196 | + return true; | ||
| 197 | + } | ||
| 198 | + return false; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + /** | ||
| 202 | + * Returns sorted import list. | ||
| 203 | + * | ||
| 204 | + * @param imports import list | ||
| 205 | + * @return sorted import list | ||
| 206 | + */ | ||
| 207 | + public static List<String> sortImports(List<String> imports) { | ||
| 208 | + sort(imports); | ||
| 209 | + return imports; | ||
| 210 | + } | ||
| 211 | + | ||
| 175 | } | 212 | } | ... | ... |
| ... | @@ -149,7 +149,7 @@ public final class YangJavaModelUtils { | ... | @@ -149,7 +149,7 @@ public final class YangJavaModelUtils { |
| 149 | /** | 149 | /** |
| 150 | * Enumeration | 150 | * Enumeration |
| 151 | */ | 151 | */ |
| 152 | - javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | 152 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles() |
| 153 | .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo); | 153 | .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo); |
| 154 | } else if (javaCodeGeneratorInfo instanceof YangChoice) { | 154 | } else if (javaCodeGeneratorInfo instanceof YangChoice) { |
| 155 | /*Do nothing, only the interface needs to be generated*/ | 155 | /*Do nothing, only the interface needs to be generated*/ | ... | ... |
| ... | @@ -41,7 +41,6 @@ public final class UtilConstants { | ... | @@ -41,7 +41,6 @@ public final class UtilConstants { |
| 41 | public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which represents the" | 41 | public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which represents the" |
| 42 | + " functionality of "; | 42 | + " functionality of "; |
| 43 | 43 | ||
| 44 | - | ||
| 45 | /** | 44 | /** |
| 46 | * JavaDocs for event. | 45 | * JavaDocs for event. |
| 47 | */ | 46 | */ |
| ... | @@ -52,7 +51,6 @@ public final class UtilConstants { | ... | @@ -52,7 +51,6 @@ public final class UtilConstants { |
| 52 | */ | 51 | */ |
| 53 | public static final String EVENT_LISTENER_JAVA_DOC = " * Abstraction for event listener of "; | 52 | public static final String EVENT_LISTENER_JAVA_DOC = " * Abstraction for event listener of "; |
| 54 | 53 | ||
| 55 | - | ||
| 56 | /** | 54 | /** |
| 57 | * JavaDocs for builder interface class. | 55 | * JavaDocs for builder interface class. |
| 58 | */ | 56 | */ |
| ... | @@ -169,6 +167,11 @@ public final class UtilConstants { | ... | @@ -169,6 +167,11 @@ public final class UtilConstants { |
| 169 | public static final String NEW_LINE = "\n"; | 167 | public static final String NEW_LINE = "\n"; |
| 170 | 168 | ||
| 171 | /** | 169 | /** |
| 170 | + * Static attribute for default. | ||
| 171 | + */ | ||
| 172 | + public static final String DEFAULT = "default"; | ||
| 173 | + | ||
| 174 | + /** | ||
| 172 | * Static attribute for multiple new line. | 175 | * Static attribute for multiple new line. |
| 173 | */ | 176 | */ |
| 174 | public static final String MULTIPLE_NEW_LINE = "\n\n"; | 177 | public static final String MULTIPLE_NEW_LINE = "\n\n"; |
| ... | @@ -434,6 +437,16 @@ public final class UtilConstants { | ... | @@ -434,6 +437,16 @@ public final class UtilConstants { |
| 434 | public static final String CLEAR = "clear"; | 437 | public static final String CLEAR = "clear"; |
| 435 | 438 | ||
| 436 | /** | 439 | /** |
| 440 | + * Static attribute for switch syntax. | ||
| 441 | + */ | ||
| 442 | + public static final String SWITCH = "switch"; | ||
| 443 | + | ||
| 444 | + /** | ||
| 445 | + * Static attribute for case syntax. | ||
| 446 | + */ | ||
| 447 | + public static final String CASE = "case"; | ||
| 448 | + | ||
| 449 | + /** | ||
| 437 | * Static attribute for temp val syntax. | 450 | * Static attribute for temp val syntax. |
| 438 | */ | 451 | */ |
| 439 | public static final String TMP_VAL = "tmpVal"; | 452 | public static final String TMP_VAL = "tmpVal"; |
| ... | @@ -703,7 +716,6 @@ public final class UtilConstants { | ... | @@ -703,7 +716,6 @@ public final class UtilConstants { |
| 703 | */ | 716 | */ |
| 704 | public static final String SERVICE = "Service"; | 717 | public static final String SERVICE = "Service"; |
| 705 | 718 | ||
| 706 | - | ||
| 707 | /** | 719 | /** |
| 708 | * Static attribute for interface syntax. | 720 | * Static attribute for interface syntax. |
| 709 | */ | 721 | */ |
| ... | @@ -875,7 +887,7 @@ public final class UtilConstants { | ... | @@ -875,7 +887,7 @@ public final class UtilConstants { |
| 875 | public static final String ARRAY_LIST = "ArrayList"; | 887 | public static final String ARRAY_LIST = "ArrayList"; |
| 876 | 888 | ||
| 877 | /** | 889 | /** |
| 878 | - * comment to be added for autogenerated impl methods. | 890 | + * Comment to be added for autogenerated impl methods. |
| 879 | */ | 891 | */ |
| 880 | public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code"; | 892 | public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code"; |
| 881 | 893 | ... | ... |
| ... | @@ -24,8 +24,9 @@ import java.io.IOException; | ... | @@ -24,8 +24,9 @@ import java.io.IOException; |
| 24 | import java.io.PrintWriter; | 24 | import java.io.PrintWriter; |
| 25 | 25 | ||
| 26 | import org.onosproject.yangutils.datamodel.YangNode; | 26 | import org.onosproject.yangutils.datamodel.YangNode; |
| 27 | -import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | 27 | +import org.onosproject.yangutils.translator.exception.TranslatorException; |
| 28 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 28 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
| 29 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | ||
| 29 | 30 | ||
| 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; | 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; |
| 31 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 32 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
| ... | @@ -35,7 +36,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ... | @@ -35,7 +36,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
| 35 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
| 36 | import static org.onosproject.yangutils.utils.UtilConstants.MULTIPLE_NEW_LINE; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.MULTIPLE_NEW_LINE; |
| 37 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
| 38 | -import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD; | ||
| 39 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
| 40 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
| 41 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo; | 41 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo; |
| ... | @@ -62,7 +62,7 @@ public final class FileSystemUtil { | ... | @@ -62,7 +62,7 @@ public final class FileSystemUtil { |
| 62 | public static boolean doesPackageExist(String pkg) { | 62 | public static boolean doesPackageExist(String pkg) { |
| 63 | File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg)); | 63 | File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg)); |
| 64 | File pkgWithFile = new File(pkgDir + SLASH + "package-info.java"); | 64 | File pkgWithFile = new File(pkgDir + SLASH + "package-info.java"); |
| 65 | - return (pkgDir.exists() && pkgWithFile.isFile()); | 65 | + return pkgDir.exists() && pkgWithFile.isFile(); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | /** | 68 | /** |
| ... | @@ -71,26 +71,24 @@ public final class FileSystemUtil { | ... | @@ -71,26 +71,24 @@ public final class FileSystemUtil { |
| 71 | * @param yangNode YANG node for which code is being generated | 71 | * @param yangNode YANG node for which code is being generated |
| 72 | * @throws IOException any IO exception | 72 | * @throws IOException any IO exception |
| 73 | */ | 73 | */ |
| 74 | - public static void createPackage(YangNode yangNode) | 74 | + public static void createPackage(YangNode yangNode) throws IOException { |
| 75 | - throws IOException { | 75 | + if (!(yangNode instanceof JavaFileInfoContainer)) { |
| 76 | - | 76 | + throw new TranslatorException("current node must have java file info"); |
| 77 | - YangNode parent = getParentNodeInGenCode(yangNode); | 77 | + } |
| 78 | - JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo(); | ||
| 79 | - String absolutePath = getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(), | ||
| 80 | - javaFileInfo.getPackageFilePath()); | ||
| 81 | - | ||
| 82 | String pkgInfo; | 78 | String pkgInfo; |
| 79 | + JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo(); | ||
| 80 | + String pkg = getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(), javaFileInfo.getPackageFilePath()); | ||
| 81 | + if (!doesPackageExist(pkg)) { | ||
| 82 | + try { | ||
| 83 | + File pack = createDirectories(pkg); | ||
| 84 | + YangNode parent = getParentNodeInGenCode(yangNode); | ||
| 83 | if (parent != null) { | 85 | if (parent != null) { |
| 84 | - pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName() | 86 | + pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName(); |
| 85 | - + PACKAGE_INFO_JAVADOC_OF_CHILD; | 87 | + addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true); |
| 86 | } else { | 88 | } else { |
| 87 | - pkgInfo = javaFileInfo.getJavaName(); | 89 | + pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName(); |
| 90 | + addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false); | ||
| 88 | } | 91 | } |
| 89 | - | ||
| 90 | - if (!doesPackageExist(absolutePath)) { | ||
| 91 | - try { | ||
| 92 | - File pack = createDirectories(absolutePath); | ||
| 93 | - addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(absolutePath)); | ||
| 94 | } catch (IOException e) { | 92 | } catch (IOException e) { |
| 95 | throw new IOException("failed to create package-info file"); | 93 | throw new IOException("failed to create package-info file"); |
| 96 | } | 94 | } | ... | ... |
| ... | @@ -19,7 +19,6 @@ package org.onosproject.yangutils.utils.io.impl; | ... | @@ -19,7 +19,6 @@ package org.onosproject.yangutils.utils.io.impl; |
| 19 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; | 19 | import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax; |
| 20 | 20 | ||
| 21 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 21 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 22 | -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | ||
| 23 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 22 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 24 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; | 23 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; |
| 25 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; | 24 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; |
| ... | @@ -54,12 +53,14 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK; | ... | @@ -54,12 +53,14 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK; |
| 54 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; | 53 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; |
| 55 | import static org.onosproject.yangutils.utils.UtilConstants.OF; | 54 | import static org.onosproject.yangutils.utils.UtilConstants.OF; |
| 56 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC; | 55 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC; |
| 56 | +import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD; | ||
| 57 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | 57 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 58 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_STRING; | 58 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_STRING; |
| 59 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_OUTPUT_STRING; | 59 | import static org.onosproject.yangutils.utils.UtilConstants.RPC_OUTPUT_STRING; |
| 60 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 60 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
| 61 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | 61 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
| 62 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE; | 62 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE; |
| 63 | +import static org.onosproject.yangutils.utils.UtilConstants.VOID; | ||
| 63 | 64 | ||
| 64 | /** | 65 | /** |
| 65 | * Represents javadoc for the generated classes. | 66 | * Represents javadoc for the generated classes. |
| ... | @@ -108,11 +109,16 @@ public final class JavaDocGen { | ... | @@ -108,11 +109,16 @@ public final class JavaDocGen { |
| 108 | GETTER_METHOD, | 109 | GETTER_METHOD, |
| 109 | 110 | ||
| 110 | /** | 111 | /** |
| 111 | - * For rpc. | 112 | + * For rpc service. |
| 112 | */ | 113 | */ |
| 113 | RPC_INTERFACE, | 114 | RPC_INTERFACE, |
| 114 | 115 | ||
| 115 | /** | 116 | /** |
| 117 | + * For rpc manager. | ||
| 118 | + */ | ||
| 119 | + RPC_MANAGER, | ||
| 120 | + | ||
| 121 | + /** | ||
| 116 | * For event. | 122 | * For event. |
| 117 | */ | 123 | */ |
| 118 | EVENT, | 124 | EVENT, |
| ... | @@ -203,7 +209,7 @@ public final class JavaDocGen { | ... | @@ -203,7 +209,7 @@ public final class JavaDocGen { |
| 203 | return generateForBuilderInterface(name); | 209 | return generateForBuilderInterface(name); |
| 204 | } | 210 | } |
| 205 | case PACKAGE_INFO: { | 211 | case PACKAGE_INFO: { |
| 206 | - return generateForPackage(name); | 212 | + return generateForPackage(name, isList); |
| 207 | } | 213 | } |
| 208 | case GETTER_METHOD: { | 214 | case GETTER_METHOD: { |
| 209 | return generateForGetters(name, isList); | 215 | return generateForGetters(name, isList); |
| ... | @@ -239,7 +245,10 @@ public final class JavaDocGen { | ... | @@ -239,7 +245,10 @@ public final class JavaDocGen { |
| 239 | return generateForEnumAttr(name); | 245 | return generateForEnumAttr(name); |
| 240 | } | 246 | } |
| 241 | case RPC_INTERFACE: { | 247 | case RPC_INTERFACE: { |
| 242 | - return generateForRpcInterface(name); | 248 | + return generateForRpcService(name); |
| 249 | + } | ||
| 250 | + case RPC_MANAGER: { | ||
| 251 | + return generateForImplClass(name); | ||
| 243 | } | 252 | } |
| 244 | case EVENT: { | 253 | case EVENT: { |
| 245 | return generateForEvent(name); | 254 | return generateForEvent(name); |
| ... | @@ -274,13 +283,14 @@ public final class JavaDocGen { | ... | @@ -274,13 +283,14 @@ public final class JavaDocGen { |
| 274 | */ | 283 | */ |
| 275 | public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName) { | 284 | public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName) { |
| 276 | rpcName = getCamelCase(rpcName, null); | 285 | rpcName = getCamelCase(rpcName, null); |
| 277 | - inputName = getCaptialCase(inputName); | ||
| 278 | - outputName = getCaptialCase(outputName); | ||
| 279 | 286 | ||
| 280 | - return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC | 287 | + String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC |
| 281 | + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK | 288 | + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK |
| 282 | - + getInputString(inputName, rpcName) + getOutputString(outputName, rpcName) + FOUR_SPACE_INDENTATION | 289 | + + getInputString(inputName, rpcName); |
| 283 | - + JAVA_DOC_END_LINE; | 290 | + if (!outputName.equals(VOID)) { |
| 291 | + javadoc = javadoc + getOutputString(outputName, rpcName); | ||
| 292 | + } | ||
| 293 | + return javadoc + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; | ||
| 284 | } | 294 | } |
| 285 | 295 | ||
| 286 | /** | 296 | /** |
| ... | @@ -315,7 +325,7 @@ public final class JavaDocGen { | ... | @@ -315,7 +325,7 @@ public final class JavaDocGen { |
| 315 | * @param interfaceName interface name | 325 | * @param interfaceName interface name |
| 316 | * @return javaDocs | 326 | * @return javaDocs |
| 317 | */ | 327 | */ |
| 318 | - private static String generateForRpcInterface(String interfaceName) { | 328 | + private static String generateForRpcService(String interfaceName) { |
| 319 | return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE | 329 | return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE |
| 320 | + JAVA_DOC_END_LINE; | 330 | + JAVA_DOC_END_LINE; |
| 321 | } | 331 | } |
| ... | @@ -436,7 +446,7 @@ public final class JavaDocGen { | ... | @@ -436,7 +446,7 @@ public final class JavaDocGen { |
| 436 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF | 446 | return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF |
| 437 | + attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD | 447 | + attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD |
| 438 | + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM | 448 | + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM |
| 439 | - + FROM_STRING_PARAM_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD + NEW_LINE | 449 | + + FROM_STRING_PARAM_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + NEW_LINE |
| 440 | + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE | 450 | + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE |
| 441 | + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; | 451 | + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
| 442 | } | 452 | } |
| ... | @@ -512,10 +522,15 @@ public final class JavaDocGen { | ... | @@ -512,10 +522,15 @@ public final class JavaDocGen { |
| 512 | * Generates javaDocs for package-info. | 522 | * Generates javaDocs for package-info. |
| 513 | * | 523 | * |
| 514 | * @param packageName package name | 524 | * @param packageName package name |
| 525 | + * @param isChildNode is it child node | ||
| 515 | * @return javaDocs | 526 | * @return javaDocs |
| 516 | */ | 527 | */ |
| 517 | - private static String generateForPackage(String packageName) { | 528 | + private static String generateForPackage(String packageName, boolean isChildNode) { |
| 518 | - return JAVA_DOC_FIRST_LINE + PACKAGE_INFO_JAVADOC + packageName + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; | 529 | + String javaDoc = JAVA_DOC_FIRST_LINE + PACKAGE_INFO_JAVADOC + packageName; |
| 530 | + if (isChildNode) { | ||
| 531 | + javaDoc = javaDoc + PACKAGE_INFO_JAVADOC_OF_CHILD; | ||
| 532 | + } | ||
| 533 | + return javaDoc + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; | ||
| 519 | } | 534 | } |
| 520 | 535 | ||
| 521 | /** | 536 | /** |
| ... | @@ -536,11 +551,10 @@ public final class JavaDocGen { | ... | @@ -536,11 +551,10 @@ public final class JavaDocGen { |
| 536 | * @return javaDocs | 551 | * @return javaDocs |
| 537 | */ | 552 | */ |
| 538 | private static String generateForConstructors(String className) { | 553 | private static String generateForConstructors(String className) { |
| 539 | - return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE | 554 | + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR |
| 540 | - + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className + IMPL + PERIOD + NEW_LINE | 555 | + + className + IMPL + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK |
| 541 | - + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM | 556 | + + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT |
| 542 | - + BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT + className + NEW_LINE | 557 | + + className + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
| 543 | - + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; | ||
| 544 | } | 558 | } |
| 545 | 559 | ||
| 546 | /** | 560 | /** | ... | ... |
| ... | @@ -23,7 +23,9 @@ import java.io.IOException; | ... | @@ -23,7 +23,9 @@ import java.io.IOException; |
| 23 | import java.nio.file.Files; | 23 | import java.nio.file.Files; |
| 24 | import java.nio.file.StandardCopyOption; | 24 | import java.nio.file.StandardCopyOption; |
| 25 | import java.util.ArrayList; | 25 | import java.util.ArrayList; |
| 26 | +import java.util.LinkedList; | ||
| 26 | import java.util.List; | 27 | import java.util.List; |
| 28 | +import java.util.Stack; | ||
| 27 | 29 | ||
| 28 | import org.apache.commons.io.FileUtils; | 30 | import org.apache.commons.io.FileUtils; |
| 29 | import org.apache.maven.model.Resource; | 31 | import org.apache.maven.model.Resource; |
| ... | @@ -80,9 +82,11 @@ public final class YangIoUtils { | ... | @@ -80,9 +82,11 @@ public final class YangIoUtils { |
| 80 | * @param path directory path | 82 | * @param path directory path |
| 81 | * @param classInfo class info for the package | 83 | * @param classInfo class info for the package |
| 82 | * @param pack package of the directory | 84 | * @param pack package of the directory |
| 85 | + * @param isChildNode is it a child node | ||
| 83 | * @throws IOException when fails to create package info file | 86 | * @throws IOException when fails to create package info file |
| 84 | */ | 87 | */ |
| 85 | - public static void addPackageInfo(File path, String classInfo, String pack) throws IOException { | 88 | + public static void addPackageInfo(File path, String classInfo, String pack, boolean isChildNode) |
| 89 | + throws IOException { | ||
| 86 | 90 | ||
| 87 | if (pack.contains(ORG)) { | 91 | if (pack.contains(ORG)) { |
| 88 | String[] strArray = pack.split(ORG); | 92 | String[] strArray = pack.split(ORG); |
| ... | @@ -97,7 +101,7 @@ public final class YangIoUtils { | ... | @@ -97,7 +101,7 @@ public final class YangIoUtils { |
| 97 | BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); | 101 | BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); |
| 98 | 102 | ||
| 99 | bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); | 103 | bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); |
| 100 | - bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, false)); | 104 | + bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode)); |
| 101 | bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN); | 105 | bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN); |
| 102 | 106 | ||
| 103 | bufferedWriter.close(); | 107 | bufferedWriter.close(); |
| ... | @@ -119,11 +123,45 @@ public final class YangIoUtils { | ... | @@ -119,11 +123,45 @@ public final class YangIoUtils { |
| 119 | try { | 123 | try { |
| 120 | FileUtils.deleteDirectory(generatedDirectory); | 124 | FileUtils.deleteDirectory(generatedDirectory); |
| 121 | } catch (IOException e) { | 125 | } catch (IOException e) { |
| 122 | - throw new IOException("Failed to delete the generated files in " + generatedDirectory + " directory"); | 126 | + throw new IOException( |
| 127 | + "Failed to delete the generated files in " + generatedDirectory + " directory"); | ||
| 128 | + } | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * Searches and deletes generated temporary directories. | ||
| 134 | + * | ||
| 135 | + * @param root root directory | ||
| 136 | + * @throws IOException when fails to do IO operations. | ||
| 137 | + */ | ||
| 138 | + public static void searchAndDeleteTempDir(String root) throws IOException { | ||
| 139 | + List<File> store = new LinkedList<>(); | ||
| 140 | + Stack<String> stack = new Stack<>(); | ||
| 141 | + stack.push(root); | ||
| 142 | + | ||
| 143 | + while (!stack.empty()) { | ||
| 144 | + root = stack.pop(); | ||
| 145 | + File file = new File(root); | ||
| 146 | + File[] filelist = file.listFiles(); | ||
| 147 | + if (filelist == null || filelist.length == 0) { | ||
| 148 | + continue; | ||
| 149 | + } | ||
| 150 | + for (File current : filelist) { | ||
| 151 | + if (current.isDirectory()) { | ||
| 152 | + stack.push(current.toString()); | ||
| 153 | + if (current.getName().endsWith("-Temp")) { | ||
| 154 | + store.add(current); | ||
| 155 | + } | ||
| 123 | } | 156 | } |
| 124 | } | 157 | } |
| 125 | } | 158 | } |
| 126 | 159 | ||
| 160 | + for (File dir : store) { | ||
| 161 | + dir.delete(); | ||
| 162 | + } | ||
| 163 | + } | ||
| 164 | + | ||
| 127 | /** | 165 | /** |
| 128 | * Adds generated source directory to the compilation root. | 166 | * Adds generated source directory to the compilation root. |
| 129 | * | 167 | * | ... | ... |
| 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 | +import java.io.IOException; | ||
| 20 | + | ||
| 21 | +import org.junit.Test; | ||
| 22 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
| 23 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
| 24 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
| 25 | + | ||
| 26 | +import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; | ||
| 27 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * Unit test case for enum translator. | ||
| 31 | + */ | ||
| 32 | +public final class EnumTranslatorTest { | ||
| 33 | + | ||
| 34 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * Checks enum translation should not result in any exception. | ||
| 38 | + */ | ||
| 39 | + @Test | ||
| 40 | + public void processEnumTranslator() | ||
| 41 | + throws IOException, ParserException { | ||
| 42 | + | ||
| 43 | + String userDir = System.getProperty("user.dir"); | ||
| 44 | + YangNode node = manager.getDataModel("src/test/resources/EnumTranslator.yang"); | ||
| 45 | + | ||
| 46 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
| 47 | + yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/"); | ||
| 48 | + | ||
| 49 | + generateJavaCode(node, yangPluginConfig); | ||
| 50 | + | ||
| 51 | + deleteDirectory(userDir + "/target/EnumTestGenFile/"); | ||
| 52 | + } | ||
| 53 | + // TODO enhance the test cases, after having a framework of translator test. | ||
| 54 | +} |
| ... | @@ -22,6 +22,7 @@ import java.lang.reflect.Constructor; | ... | @@ -22,6 +22,7 @@ import java.lang.reflect.Constructor; |
| 22 | import java.lang.reflect.InvocationTargetException; | 22 | import java.lang.reflect.InvocationTargetException; |
| 23 | 23 | ||
| 24 | import org.junit.Test; | 24 | import org.junit.Test; |
| 25 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
| 25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
| 26 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; | 27 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; |
| 27 | 28 | ||
| ... | @@ -41,11 +42,14 @@ import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileH | ... | @@ -41,11 +42,14 @@ import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileH |
| 41 | public final class FileSystemUtilTest { | 42 | public final class FileSystemUtilTest { |
| 42 | 43 | ||
| 43 | private static final String BASE_DIR_PKG = "target.UnitTestCase."; | 44 | private static final String BASE_DIR_PKG = "target.UnitTestCase."; |
| 44 | - private static final String PKG_INFO_CONTENT = "testGeneration6"; | ||
| 45 | private static final String BASE_PKG = "target/UnitTestCase"; | 45 | private static final String BASE_PKG = "target/UnitTestCase"; |
| 46 | private static final String TEST_DATA_1 = "This is to append a text to the file first1\n"; | 46 | private static final String TEST_DATA_1 = "This is to append a text to the file first1\n"; |
| 47 | private static final String TEST_DATA_2 = "This is next second line\n"; | 47 | private static final String TEST_DATA_2 = "This is next second line\n"; |
| 48 | private static final String TEST_DATA_3 = "This is next third line in the file"; | 48 | private static final String TEST_DATA_3 = "This is next third line in the file"; |
| 49 | + private static final String TEST_FILE = "testFile"; | ||
| 50 | + private static final String SOURCE_TEST_FILE = "sourceTestFile"; | ||
| 51 | + private static final String DIR_PATH = "exist1.exist2.exist3"; | ||
| 52 | + private static final String PKG_INFO = "package-info.java"; | ||
| 49 | 53 | ||
| 50 | /** | 54 | /** |
| 51 | * A private constructor is tested. | 55 | * A private constructor is tested. |
| ... | @@ -62,7 +66,7 @@ public final class FileSystemUtilTest { | ... | @@ -62,7 +66,7 @@ public final class FileSystemUtilTest { |
| 62 | throws SecurityException, NoSuchMethodException, IllegalArgumentException, | 66 | throws SecurityException, NoSuchMethodException, IllegalArgumentException, |
| 63 | InstantiationException, IllegalAccessException, InvocationTargetException { | 67 | InstantiationException, IllegalAccessException, InvocationTargetException { |
| 64 | 68 | ||
| 65 | - Class<?>[] classesToConstruct = {FileSystemUtil.class}; | 69 | + Class<?>[] classesToConstruct = {FileSystemUtil.class }; |
| 66 | for (Class<?> clazz : classesToConstruct) { | 70 | for (Class<?> clazz : classesToConstruct) { |
| 67 | Constructor<?> constructor = clazz.getDeclaredConstructor(); | 71 | Constructor<?> constructor = clazz.getDeclaredConstructor(); |
| 68 | constructor.setAccessible(true); | 72 | constructor.setAccessible(true); |
| ... | @@ -76,14 +80,13 @@ public final class FileSystemUtilTest { | ... | @@ -76,14 +80,13 @@ public final class FileSystemUtilTest { |
| 76 | * @throws IOException when fails to create a test file | 80 | * @throws IOException when fails to create a test file |
| 77 | */ | 81 | */ |
| 78 | @Test | 82 | @Test |
| 79 | - public void updateFileHandleTest() | 83 | + public void updateFileHandleTest() throws IOException { |
| 80 | - throws IOException { | ||
| 81 | 84 | ||
| 82 | - File dir = new File(BASE_PKG + SLASH + "File1"); | 85 | + File dir = new File(BASE_PKG + SLASH + TEST_FILE); |
| 83 | dir.mkdirs(); | 86 | dir.mkdirs(); |
| 84 | - File createFile = new File(dir + "testFile"); | 87 | + File createFile = new File(dir + TEST_FILE); |
| 85 | createFile.createNewFile(); | 88 | createFile.createNewFile(); |
| 86 | - File createSourceFile = new File(dir + "sourceTestFile"); | 89 | + File createSourceFile = new File(dir + SOURCE_TEST_FILE); |
| 87 | createSourceFile.createNewFile(); | 90 | createSourceFile.createNewFile(); |
| 88 | updateFileHandle(createFile, TEST_DATA_1, false); | 91 | updateFileHandle(createFile, TEST_DATA_1, false); |
| 89 | updateFileHandle(createFile, TEST_DATA_2, false); | 92 | updateFileHandle(createFile, TEST_DATA_2, false); |
| ... | @@ -98,23 +101,31 @@ public final class FileSystemUtilTest { | ... | @@ -98,23 +101,31 @@ public final class FileSystemUtilTest { |
| 98 | * @throws IOException when failed to create a test file | 101 | * @throws IOException when failed to create a test file |
| 99 | */ | 102 | */ |
| 100 | @Test | 103 | @Test |
| 101 | - public void packageExistTest() | 104 | + public void packageExistTest() throws IOException { |
| 102 | - throws IOException { | ||
| 103 | 105 | ||
| 104 | - String dirPath = "exist1.exist2.exist3"; | 106 | + String strPath = BASE_DIR_PKG + DIR_PATH; |
| 105 | - String strPath = BASE_DIR_PKG + dirPath; | ||
| 106 | File createDir = new File(strPath.replace(PERIOD, SLASH)); | 107 | File createDir = new File(strPath.replace(PERIOD, SLASH)); |
| 107 | createDir.mkdirs(); | 108 | createDir.mkdirs(); |
| 108 | - File createFile = new File(createDir + SLASH + "package-info.java"); | 109 | + File createFile = new File(createDir + SLASH + PKG_INFO); |
| 109 | createFile.createNewFile(); | 110 | createFile.createNewFile(); |
| 110 | assertThat(true, is(doesPackageExist(strPath))); | 111 | assertThat(true, is(doesPackageExist(strPath))); |
| 111 | - JavaFileInfo javaFileInfo = new JavaFileInfo(); | 112 | + createPackage(getStubNode()); |
| 112 | - javaFileInfo.setBaseCodeGenPath(BASE_DIR_PKG); | ||
| 113 | - javaFileInfo.setPackageFilePath(dirPath); | ||
| 114 | - YangJavaModule moduleNode = new YangJavaModule(); | ||
| 115 | - moduleNode.setJavaFileInfo(javaFileInfo); | ||
| 116 | - createPackage(moduleNode); | ||
| 117 | createDir.delete(); | 113 | createDir.delete(); |
| 118 | } | 114 | } |
| 119 | 115 | ||
| 116 | + /** | ||
| 117 | + * Returns stub YANG node. | ||
| 118 | + * | ||
| 119 | + * @return stub node | ||
| 120 | + */ | ||
| 121 | + private YangNode getStubNode() { | ||
| 122 | + YangJavaModule module = new YangJavaModule(); | ||
| 123 | + module.setName(TEST_DATA_1); | ||
| 124 | + JavaFileInfo javafileInfo = new JavaFileInfo(); | ||
| 125 | + javafileInfo.setJavaName(TEST_DATA_1); | ||
| 126 | + javafileInfo.setBaseCodeGenPath(""); | ||
| 127 | + javafileInfo.setPackageFilePath(BASE_PKG); | ||
| 128 | + module.setJavaFileInfo(javafileInfo); | ||
| 129 | + return module; | ||
| 130 | + } | ||
| 120 | } | 131 | } | ... | ... |
| ... | @@ -51,7 +51,7 @@ public final class JavaDocGenTest { | ... | @@ -51,7 +51,7 @@ public final class JavaDocGenTest { |
| 51 | public ExpectedException thrown = ExpectedException.none(); | 51 | public ExpectedException thrown = ExpectedException.none(); |
| 52 | 52 | ||
| 53 | /** | 53 | /** |
| 54 | - * This test case checks the content recieved for the builder class java doc. | 54 | + * This test case checks the content received for the builder class java doc. |
| 55 | */ | 55 | */ |
| 56 | @Test | 56 | @Test |
| 57 | public void builderClassGenerationTest() { | 57 | public void builderClassGenerationTest() { |
| ... | @@ -61,7 +61,7 @@ public final class JavaDocGenTest { | ... | @@ -61,7 +61,7 @@ public final class JavaDocGenTest { |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | /** | 63 | /** |
| 64 | - * This test case checks the content recieved for the builder interface ge java doc. | 64 | + * This test case checks the content received for the builder interface ge java doc. |
| 65 | */ | 65 | */ |
| 66 | @Test | 66 | @Test |
| 67 | public void builderInterfaceGenerationTest() { | 67 | public void builderInterfaceGenerationTest() { |
| ... | @@ -71,7 +71,7 @@ public final class JavaDocGenTest { | ... | @@ -71,7 +71,7 @@ public final class JavaDocGenTest { |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | /** | 73 | /** |
| 74 | - * This test case checks the content recieved for the build java doc. | 74 | + * This test case checks the content received for the build java doc. |
| 75 | */ | 75 | */ |
| 76 | @Test | 76 | @Test |
| 77 | public void buildGenerationTest() { | 77 | public void buildGenerationTest() { |
| ... | @@ -102,7 +102,7 @@ public final class JavaDocGenTest { | ... | @@ -102,7 +102,7 @@ public final class JavaDocGenTest { |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | /** | 104 | /** |
| 105 | - * This test case checks the content recieved for the constructor java doc. | 105 | + * This test case checks the content received for the constructor java doc. |
| 106 | */ | 106 | */ |
| 107 | @Test | 107 | @Test |
| 108 | public void constructorGenerationTest() { | 108 | public void constructorGenerationTest() { |
| ... | @@ -113,7 +113,7 @@ public final class JavaDocGenTest { | ... | @@ -113,7 +113,7 @@ public final class JavaDocGenTest { |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | /** | 115 | /** |
| 116 | - * This test case checks the content recieved for the default constructor java doc. | 116 | + * This test case checks the content received for the default constructor java doc. |
| 117 | */ | 117 | */ |
| 118 | @Test | 118 | @Test |
| 119 | public void defaultConstructorGenerationTest() { | 119 | public void defaultConstructorGenerationTest() { |
| ... | @@ -123,7 +123,7 @@ public final class JavaDocGenTest { | ... | @@ -123,7 +123,7 @@ public final class JavaDocGenTest { |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | /** | 125 | /** |
| 126 | - * This test case checks the content recieved for the getter java doc. | 126 | + * This test case checks the content received for the getter java doc. |
| 127 | */ | 127 | */ |
| 128 | @Test | 128 | @Test |
| 129 | public void getterGenerationTest() { | 129 | public void getterGenerationTest() { |
| ... | @@ -132,7 +132,7 @@ public final class JavaDocGenTest { | ... | @@ -132,7 +132,7 @@ public final class JavaDocGenTest { |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | /** | 134 | /** |
| 135 | - * This test case checks the content recieved for the impl class java doc. | 135 | + * This test case checks the content received for the impl class java doc. |
| 136 | */ | 136 | */ |
| 137 | @Test | 137 | @Test |
| 138 | public void implClassGenerationTest() { | 138 | public void implClassGenerationTest() { |
| ... | @@ -143,7 +143,7 @@ public final class JavaDocGenTest { | ... | @@ -143,7 +143,7 @@ public final class JavaDocGenTest { |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | /** | 145 | /** |
| 146 | - * This test case checks the content recieved for the interface java doc. | 146 | + * This test case checks the content received for the interface java doc. |
| 147 | */ | 147 | */ |
| 148 | @Test | 148 | @Test |
| 149 | public void interfaceGenerationTest() { | 149 | public void interfaceGenerationTest() { |
| ... | @@ -154,7 +154,7 @@ public final class JavaDocGenTest { | ... | @@ -154,7 +154,7 @@ public final class JavaDocGenTest { |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | /** | 156 | /** |
| 157 | - * This test case checks the content recieved for the package info java doc. | 157 | + * This test case checks the content received for the package info java doc. |
| 158 | */ | 158 | */ |
| 159 | @Test | 159 | @Test |
| 160 | public void packageInfoGenerationTest() { | 160 | public void packageInfoGenerationTest() { |
| ... | @@ -163,7 +163,17 @@ public final class JavaDocGenTest { | ... | @@ -163,7 +163,17 @@ public final class JavaDocGenTest { |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | /** | 165 | /** |
| 166 | - * This test case checks the content recieved for the setter java doc. | 166 | + * This test case checks the content received for the package info java doc. |
| 167 | + */ | ||
| 168 | + @Test | ||
| 169 | + public void packageInfoGenerationForChildNodeTest() { | ||
| 170 | + String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true); | ||
| 171 | + assertThat(true, is(packageInfo.contains("Implementation of YANG node testName's children nodes") | ||
| 172 | + && packageInfo.contains(END_STRING))); | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + /** | ||
| 176 | + * This test case checks the content received for the setter java doc. | ||
| 167 | */ | 177 | */ |
| 168 | @Test | 178 | @Test |
| 169 | public void setterGenerationTest() { | 179 | public void setterGenerationTest() { | ... | ... |
| ... | @@ -47,6 +47,10 @@ public final class YangIoUtilsTest { | ... | @@ -47,6 +47,10 @@ public final class YangIoUtilsTest { |
| 47 | private static final String CREATE_PATH = BASE_DIR + File.separator + "dir1/dir2/dir3/dir4/"; | 47 | private static final String CREATE_PATH = BASE_DIR + File.separator + "dir1/dir2/dir3/dir4/"; |
| 48 | private static final String CHECK_STRING = "one, two, three, four, five, six"; | 48 | private static final String CHECK_STRING = "one, two, three, four, five, six"; |
| 49 | private static final String TRIM_STRING = "one, two, three, four, five, "; | 49 | private static final String TRIM_STRING = "one, two, three, four, five, "; |
| 50 | + private static final String CHECK1 = "check1"; | ||
| 51 | + private static final String PKG_INFO = "package-info.java"; | ||
| 52 | + private static final String PATH = "src/main/yangmodel/"; | ||
| 53 | + private static final String MSG = "Exception occured while creating package info file."; | ||
| 50 | 54 | ||
| 51 | /** | 55 | /** |
| 52 | * Expected exceptions. | 56 | * Expected exceptions. |
| ... | @@ -64,8 +68,8 @@ public final class YangIoUtilsTest { | ... | @@ -64,8 +68,8 @@ public final class YangIoUtilsTest { |
| 64 | 68 | ||
| 65 | File dirPath = new File(CREATE_PATH); | 69 | File dirPath = new File(CREATE_PATH); |
| 66 | dirPath.mkdirs(); | 70 | dirPath.mkdirs(); |
| 67 | - addPackageInfo(dirPath, "check1", CREATE_PATH); | 71 | + addPackageInfo(dirPath, CHECK1, CREATE_PATH, false); |
| 68 | - File filePath = new File(dirPath + File.separator + "package-info.java"); | 72 | + File filePath = new File(dirPath + File.separator + PKG_INFO); |
| 69 | assertThat(filePath.isFile(), is(true)); | 73 | assertThat(filePath.isFile(), is(true)); |
| 70 | } | 74 | } |
| 71 | 75 | ||
| ... | @@ -79,8 +83,23 @@ public final class YangIoUtilsTest { | ... | @@ -79,8 +83,23 @@ public final class YangIoUtilsTest { |
| 79 | 83 | ||
| 80 | File dirPath = new File(CREATE_PATH); | 84 | File dirPath = new File(CREATE_PATH); |
| 81 | dirPath.mkdirs(); | 85 | dirPath.mkdirs(); |
| 82 | - addPackageInfo(dirPath, "check1", "src/main/yangmodel/" + CREATE_PATH); | 86 | + addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false); |
| 83 | - File filePath = new File(dirPath + File.separator + "package-info.java"); | 87 | + File filePath = new File(dirPath + File.separator + PKG_INFO); |
| 88 | + assertThat(filePath.isFile(), is(true)); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * This test case checks with a child node. | ||
| 93 | + * | ||
| 94 | + * @throws IOException when fails to do IO operations for test case | ||
| 95 | + */ | ||
| 96 | + @Test | ||
| 97 | + public void addPackageInfoWithChildNode() throws IOException { | ||
| 98 | + | ||
| 99 | + File dirPath = new File(CREATE_PATH); | ||
| 100 | + dirPath.mkdirs(); | ||
| 101 | + addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true); | ||
| 102 | + File filePath = new File(dirPath + File.separator + PKG_INFO); | ||
| 84 | assertThat(filePath.isFile(), is(true)); | 103 | assertThat(filePath.isFile(), is(true)); |
| 85 | } | 104 | } |
| 86 | 105 | ||
| ... | @@ -94,9 +113,9 @@ public final class YangIoUtilsTest { | ... | @@ -94,9 +113,9 @@ public final class YangIoUtilsTest { |
| 94 | 113 | ||
| 95 | File dirPath = new File("invalid/check"); | 114 | File dirPath = new File("invalid/check"); |
| 96 | thrown.expect(IOException.class); | 115 | thrown.expect(IOException.class); |
| 97 | - thrown.expectMessage("Exception occured while creating package info file."); | 116 | + thrown.expectMessage(MSG); |
| 98 | - addPackageInfo(dirPath, "check1", CREATE_PATH); | 117 | + addPackageInfo(dirPath, CHECK1, CREATE_PATH, false); |
| 99 | - File filePath1 = new File(dirPath + File.separator + "package-info.java"); | 118 | + File filePath1 = new File(dirPath + File.separator + PKG_INFO); |
| 100 | assertThat(filePath1.isFile(), is(false)); | 119 | assertThat(filePath1.isFile(), is(false)); |
| 101 | } | 120 | } |
| 102 | 121 | ... | ... |
-
Please register or login to post a comment