Committed by
Ray Milkey
[ONOS-4616] YANG grouping linker issues fixed.
Change-Id: I741aa9ad1008c02c9a9f90cc117cd43729132129
Showing
28 changed files
with
541 additions
and
394 deletions
... | @@ -225,9 +225,7 @@ public class YangDerivedInfo<T> implements LocationInfo { | ... | @@ -225,9 +225,7 @@ public class YangDerivedInfo<T> implements LocationInfo { |
225 | * @throws DataModelException a violation in data mode rule | 225 | * @throws DataModelException a violation in data mode rule |
226 | */ | 226 | */ |
227 | public ResolvableStatus resolve() throws DataModelException { | 227 | public ResolvableStatus resolve() throws DataModelException { |
228 | - | ||
229 | YangType<?> baseType = getReferredTypeDef().getTypeDefBaseType(); | 228 | YangType<?> baseType = getReferredTypeDef().getTypeDefBaseType(); |
230 | - | ||
231 | /* | 229 | /* |
232 | * Checks the data type of the referred typedef, if it's derived, | 230 | * Checks the data type of the referred typedef, if it's derived, |
233 | * obtain effective built-in type and restrictions from it's derived | 231 | * obtain effective built-in type and restrictions from it's derived |
... | @@ -240,7 +238,6 @@ public class YangDerivedInfo<T> implements LocationInfo { | ... | @@ -240,7 +238,6 @@ public class YangDerivedInfo<T> implements LocationInfo { |
240 | if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) { | 238 | if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) { |
241 | throw new DataModelException("Linker Error: Referred typedef is not resolved for type."); | 239 | throw new DataModelException("Linker Error: Referred typedef is not resolved for type."); |
242 | } | 240 | } |
243 | - | ||
244 | /* | 241 | /* |
245 | * Check if the referred typedef is intra file resolved, if yes sets | 242 | * Check if the referred typedef is intra file resolved, if yes sets |
246 | * current status also to intra file resolved . | 243 | * current status also to intra file resolved . |
... | @@ -250,7 +247,7 @@ public class YangDerivedInfo<T> implements LocationInfo { | ... | @@ -250,7 +247,7 @@ public class YangDerivedInfo<T> implements LocationInfo { |
250 | } | 247 | } |
251 | setEffectiveBuiltInType(((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo()) | 248 | setEffectiveBuiltInType(((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo()) |
252 | .getEffectiveBuiltInType()); | 249 | .getEffectiveBuiltInType()); |
253 | - YangDerivedInfo refDerivedInfo = ((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo()); | 250 | + YangDerivedInfo refDerivedInfo = (YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo(); |
254 | /* | 251 | /* |
255 | * Check whether the effective built-in type can have range | 252 | * Check whether the effective built-in type can have range |
256 | * restrictions, if yes call resolution of range. | 253 | * restrictions, if yes call resolution of range. |
... | @@ -327,7 +324,7 @@ public class YangDerivedInfo<T> implements LocationInfo { | ... | @@ -327,7 +324,7 @@ public class YangDerivedInfo<T> implements LocationInfo { |
327 | } | 324 | } |
328 | } | 325 | } |
329 | } else { | 326 | } else { |
330 | - setEffectiveBuiltInType((baseType.getDataType())); | 327 | + setEffectiveBuiltInType(baseType.getDataType()); |
331 | /* | 328 | /* |
332 | * Check whether the effective built-in type can have range | 329 | * Check whether the effective built-in type can have range |
333 | * restrictions, if yes call resolution of range. | 330 | * restrictions, if yes call resolution of range. |
... | @@ -404,7 +401,6 @@ public class YangDerivedInfo<T> implements LocationInfo { | ... | @@ -404,7 +401,6 @@ public class YangDerivedInfo<T> implements LocationInfo { |
404 | } | 401 | } |
405 | } | 402 | } |
406 | } | 403 | } |
407 | - | ||
408 | /* | 404 | /* |
409 | * Check if the data type is the one which can't be restricted, in | 405 | * Check if the data type is the one which can't be restricted, in |
410 | * this case check whether no self restrictions should be present. | 406 | * this case check whether no self restrictions should be present. |
... | @@ -418,7 +414,6 @@ public class YangDerivedInfo<T> implements LocationInfo { | ... | @@ -418,7 +414,6 @@ public class YangDerivedInfo<T> implements LocationInfo { |
418 | throw new DataModelException("YANG file error: Restrictions can't be applied to a given type"); | 414 | throw new DataModelException("YANG file error: Restrictions can't be applied to a given type"); |
419 | } | 415 | } |
420 | } | 416 | } |
421 | - | ||
422 | // Throw exception for unsupported types | 417 | // Throw exception for unsupported types |
423 | throw new DataModelException("Linker error: Unable to process the derived type."); | 418 | throw new DataModelException("Linker error: Unable to process the derived type."); |
424 | } | 419 | } |
... | @@ -438,7 +433,7 @@ public class YangDerivedInfo<T> implements LocationInfo { | ... | @@ -438,7 +433,7 @@ public class YangDerivedInfo<T> implements LocationInfo { |
438 | * Check that range restriction should be null when built-in type is | 433 | * Check that range restriction should be null when built-in type is |
439 | * string. | 434 | * string. |
440 | */ | 435 | */ |
441 | - if (!(Strings.isNullOrEmpty(getRangeRestrictionString()))) { | 436 | + if (!Strings.isNullOrEmpty(getRangeRestrictionString())) { |
442 | DataModelException dataModelException = new DataModelException("YANG file error: Range restriction " + | 437 | DataModelException dataModelException = new DataModelException("YANG file error: Range restriction " + |
443 | "should't be present for string data type."); | 438 | "should't be present for string data type."); |
444 | dataModelException.setLine(lineNumber); | 439 | dataModelException.setLine(lineNumber); |
... | @@ -605,7 +600,7 @@ public class YangDerivedInfo<T> implements LocationInfo { | ... | @@ -605,7 +600,7 @@ public class YangDerivedInfo<T> implements LocationInfo { |
605 | * Check that string restriction should be null when built-in type is | 600 | * Check that string restriction should be null when built-in type is |
606 | * of range type. | 601 | * of range type. |
607 | */ | 602 | */ |
608 | - if (!(Strings.isNullOrEmpty(getLengthRestrictionString())) || getPatternRestriction() != null) { | 603 | + if (!Strings.isNullOrEmpty(getLengthRestrictionString()) || getPatternRestriction() != null) { |
609 | DataModelException dataModelException = new DataModelException("YANG file error: Length/Pattern " + | 604 | DataModelException dataModelException = new DataModelException("YANG file error: Length/Pattern " + |
610 | "restriction should't be present for int/uint/decimal data type."); | 605 | "restriction should't be present for int/uint/decimal data type."); |
611 | dataModelException.setLine(lineNumber); | 606 | dataModelException.setLine(lineNumber); |
... | @@ -660,12 +655,12 @@ public class YangDerivedInfo<T> implements LocationInfo { | ... | @@ -660,12 +655,12 @@ public class YangDerivedInfo<T> implements LocationInfo { |
660 | * @return true, if data type can't be restricted, false otherwise | 655 | * @return true, if data type can't be restricted, false otherwise |
661 | */ | 656 | */ |
662 | private boolean isOfValidNonRestrictedType(YangDataTypes dataType) { | 657 | private boolean isOfValidNonRestrictedType(YangDataTypes dataType) { |
663 | - return (dataType == BOOLEAN | 658 | + return dataType == BOOLEAN |
664 | || dataType == ENUMERATION | 659 | || dataType == ENUMERATION |
665 | || dataType == BITS | 660 | || dataType == BITS |
666 | || dataType == EMPTY | 661 | || dataType == EMPTY |
667 | || dataType == UNION | 662 | || dataType == UNION |
668 | || dataType == IDENTITYREF | 663 | || dataType == IDENTITYREF |
669 | - || dataType == LEAFREF); | 664 | + || dataType == LEAFREF; |
670 | } | 665 | } |
671 | } | 666 | } | ... | ... |
... | @@ -271,6 +271,7 @@ public class YangModule extends YangNode | ... | @@ -271,6 +271,7 @@ public class YangModule extends YangNode |
271 | * | 271 | * |
272 | * @return the list of imported modules | 272 | * @return the list of imported modules |
273 | */ | 273 | */ |
274 | + @Override | ||
274 | public List<YangImport> getImportList() { | 275 | public List<YangImport> getImportList() { |
275 | return importList; | 276 | return importList; |
276 | } | 277 | } |
... | @@ -280,6 +281,7 @@ public class YangModule extends YangNode | ... | @@ -280,6 +281,7 @@ public class YangModule extends YangNode |
280 | * | 281 | * |
281 | * @param importedModule module being imported | 282 | * @param importedModule module being imported |
282 | */ | 283 | */ |
284 | + @Override | ||
283 | public void addToImportList(YangImport importedModule) { | 285 | public void addToImportList(YangImport importedModule) { |
284 | getImportList().add(importedModule); | 286 | getImportList().add(importedModule); |
285 | } | 287 | } |
... | @@ -294,6 +296,7 @@ public class YangModule extends YangNode | ... | @@ -294,6 +296,7 @@ public class YangModule extends YangNode |
294 | * | 296 | * |
295 | * @return the included list of sub modules | 297 | * @return the included list of sub modules |
296 | */ | 298 | */ |
299 | + @Override | ||
297 | public List<YangInclude> getIncludeList() { | 300 | public List<YangInclude> getIncludeList() { |
298 | return includeList; | 301 | return includeList; |
299 | } | 302 | } |
... | @@ -303,6 +306,7 @@ public class YangModule extends YangNode | ... | @@ -303,6 +306,7 @@ public class YangModule extends YangNode |
303 | * | 306 | * |
304 | * @param includeModule submodule being included | 307 | * @param includeModule submodule being included |
305 | */ | 308 | */ |
309 | + @Override | ||
306 | public void addToIncludeList(YangInclude includeModule) { | 310 | public void addToIncludeList(YangInclude includeModule) { |
307 | getIncludeList().add(includeModule); | 311 | getIncludeList().add(includeModule); |
308 | } | 312 | } |
... | @@ -393,6 +397,7 @@ public class YangModule extends YangNode | ... | @@ -393,6 +397,7 @@ public class YangModule extends YangNode |
393 | * | 397 | * |
394 | * @return the prefix | 398 | * @return the prefix |
395 | */ | 399 | */ |
400 | + @Override | ||
396 | public String getPrefix() { | 401 | public String getPrefix() { |
397 | return prefix; | 402 | return prefix; |
398 | } | 403 | } |
... | @@ -402,6 +407,7 @@ public class YangModule extends YangNode | ... | @@ -402,6 +407,7 @@ public class YangModule extends YangNode |
402 | * | 407 | * |
403 | * @param prefix the prefix to set | 408 | * @param prefix the prefix to set |
404 | */ | 409 | */ |
410 | + @Override | ||
405 | public void setPrefix(String prefix) { | 411 | public void setPrefix(String prefix) { |
406 | this.prefix = prefix; | 412 | this.prefix = prefix; |
407 | } | 413 | } | ... | ... |
... | @@ -285,6 +285,7 @@ public class YangSubModule extends YangNode | ... | @@ -285,6 +285,7 @@ public class YangSubModule extends YangNode |
285 | * | 285 | * |
286 | * @return the list of imported modules | 286 | * @return the list of imported modules |
287 | */ | 287 | */ |
288 | + @Override | ||
288 | public List<YangImport> getImportList() { | 289 | public List<YangImport> getImportList() { |
289 | return importList; | 290 | return importList; |
290 | } | 291 | } |
... | @@ -294,6 +295,7 @@ public class YangSubModule extends YangNode | ... | @@ -294,6 +295,7 @@ public class YangSubModule extends YangNode |
294 | * | 295 | * |
295 | * @param importedModule module being imported | 296 | * @param importedModule module being imported |
296 | */ | 297 | */ |
298 | + @Override | ||
297 | public void addToImportList(YangImport importedModule) { | 299 | public void addToImportList(YangImport importedModule) { |
298 | getImportList().add(importedModule); | 300 | getImportList().add(importedModule); |
299 | } | 301 | } |
... | @@ -308,6 +310,7 @@ public class YangSubModule extends YangNode | ... | @@ -308,6 +310,7 @@ public class YangSubModule extends YangNode |
308 | * | 310 | * |
309 | * @return the included list of sub modules | 311 | * @return the included list of sub modules |
310 | */ | 312 | */ |
313 | + @Override | ||
311 | public List<YangInclude> getIncludeList() { | 314 | public List<YangInclude> getIncludeList() { |
312 | return includeList; | 315 | return includeList; |
313 | } | 316 | } |
... | @@ -317,6 +320,7 @@ public class YangSubModule extends YangNode | ... | @@ -317,6 +320,7 @@ public class YangSubModule extends YangNode |
317 | * | 320 | * |
318 | * @param includeModule submodule being included | 321 | * @param includeModule submodule being included |
319 | */ | 322 | */ |
323 | + @Override | ||
320 | public void addToIncludeList(YangInclude includeModule) { | 324 | public void addToIncludeList(YangInclude includeModule) { |
321 | getIncludeList().add(includeModule); | 325 | getIncludeList().add(includeModule); |
322 | } | 326 | } | ... | ... |
... | @@ -187,7 +187,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, Y | ... | @@ -187,7 +187,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, Y |
187 | * @return the data type | 187 | * @return the data type |
188 | */ | 188 | */ |
189 | public YangType<?> getTypeDefBaseType() { | 189 | public YangType<?> getTypeDefBaseType() { |
190 | - if (!(getTypeList().isEmpty())) { | 190 | + if (!getTypeList().isEmpty()) { |
191 | return getTypeList().get(0); | 191 | return getTypeList().get(0); |
192 | } | 192 | } |
193 | return null; | 193 | return null; | ... | ... |
... | @@ -271,8 +271,8 @@ public class YangUses | ... | @@ -271,8 +271,8 @@ public class YangUses |
271 | } | 271 | } |
272 | 272 | ||
273 | YangNode usesParentNode = getParentNodeInGenCode(this); | 273 | YangNode usesParentNode = getParentNodeInGenCode(this); |
274 | - if ((!(usesParentNode instanceof YangLeavesHolder)) | 274 | + if (!(usesParentNode instanceof YangLeavesHolder) |
275 | - || (!(usesParentNode instanceof CollisionDetector))) { | 275 | + || !(usesParentNode instanceof CollisionDetector)) { |
276 | throw new LinkerException("Linker Exception: YANG uses holder construct is wrong"); | 276 | throw new LinkerException("Linker Exception: YANG uses holder construct is wrong"); |
277 | } | 277 | } |
278 | 278 | ... | ... |
... | @@ -696,7 +696,7 @@ public class YangResolutionInfo<T> implements LocationInfo { | ... | @@ -696,7 +696,7 @@ public class YangResolutionInfo<T> implements LocationInfo { |
696 | * Check if prefix is null or not, to identify whether to search | 696 | * Check if prefix is null or not, to identify whether to search |
697 | * in import list or include list. | 697 | * in import list or include list. |
698 | */ | 698 | */ |
699 | - if (getRefPrefix() != null && !(getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix()))) { | 699 | + if (getRefPrefix() != null && !getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix())) { |
700 | if (resolveWithImport()) { | 700 | if (resolveWithImport()) { |
701 | return; | 701 | return; |
702 | } | 702 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
... | @@ -77,23 +77,8 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -77,23 +77,8 @@ public final class JavaCodeGeneratorUtil { |
77 | 77 | ||
78 | while (codeGenNode != null) { | 78 | while (codeGenNode != null) { |
79 | if (curTraversal != PARENT) { | 79 | if (curTraversal != PARENT) { |
80 | - if (codeGenNode instanceof JavaCodeGenerator) { | 80 | + setCurNode(codeGenNode); |
81 | - setCurNode(codeGenNode); | 81 | + generateCodeEntry(codeGenNode, yangPlugin); |
82 | - generateCodeEntry(codeGenNode, yangPlugin); | ||
83 | - } else { | ||
84 | - /* | ||
85 | - * For grouping and uses, there is no code generation, skip the generation for the child. | ||
86 | - */ | ||
87 | - if (codeGenNode.getNextSibling() != null) { | ||
88 | - curTraversal = SIBILING; | ||
89 | - codeGenNode = codeGenNode.getNextSibling(); | ||
90 | - } else { | ||
91 | - curTraversal = PARENT; | ||
92 | - codeGenNode = codeGenNode.getParent(); | ||
93 | - } | ||
94 | - continue; | ||
95 | - } | ||
96 | - | ||
97 | } | 82 | } |
98 | if (curTraversal != PARENT && codeGenNode.getChild() != null) { | 83 | if (curTraversal != PARENT && codeGenNode.getChild() != null) { |
99 | curTraversal = CHILD; | 84 | curTraversal = CHILD; | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
... | @@ -112,7 +112,7 @@ public class JavaQualifiedTypeInfo | ... | @@ -112,7 +112,7 @@ public class JavaQualifiedTypeInfo |
112 | */ | 112 | */ |
113 | importInfo.setClassInfo(className); | 113 | importInfo.setClassInfo(className); |
114 | String classPkg = AttributesJavaDataType.getJavaImportPackage(leaf.getDataType(), | 114 | String classPkg = AttributesJavaDataType.getJavaImportPackage(leaf.getDataType(), |
115 | - leaf.isLeafList(), className, leaf.getConflictResolveConfig()); | 115 | + leaf.isLeafList(), leaf.getConflictResolveConfig()); |
116 | if (classPkg == null) { | 116 | if (classPkg == null) { |
117 | throw new TranslatorException("import package cannot be null when the class is used"); | 117 | throw new TranslatorException("import package cannot be null when the class is used"); |
118 | } | 118 | } |
... | @@ -180,7 +180,7 @@ public class JavaQualifiedTypeInfo | ... | @@ -180,7 +180,7 @@ public class JavaQualifiedTypeInfo |
180 | qualifiedInfoOfFromString.setClassInfo( | 180 | qualifiedInfoOfFromString.setClassInfo( |
181 | getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true, conflictResolver)); | 181 | getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true, conflictResolver)); |
182 | qualifiedInfoOfFromString.setPkgInfo( | 182 | qualifiedInfoOfFromString.setPkgInfo( |
183 | - getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, null, conflictResolver)); | 183 | + getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, conflictResolver)); |
184 | return qualifiedInfoOfFromString; | 184 | return qualifiedInfoOfFromString; |
185 | } | 185 | } |
186 | 186 | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
... | @@ -28,6 +28,12 @@ import org.onosproject.yangutils.datamodel.YangLeavesHolder; | ... | @@ -28,6 +28,12 @@ import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
28 | import org.onosproject.yangutils.datamodel.YangNode; | 28 | import org.onosproject.yangutils.datamodel.YangNode; |
29 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 29 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
30 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; | 30 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; |
31 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping; | ||
32 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput; | ||
33 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; | ||
34 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput; | ||
35 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule; | ||
36 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses; | ||
31 | import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; | 37 | import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; |
32 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 38 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
33 | 39 | ||
... | @@ -61,6 +67,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy | ... | @@ -61,6 +67,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy |
61 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | 67 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
62 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 68 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
63 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; | 69 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; |
70 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; | ||
64 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; | 71 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; |
65 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; | 72 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; |
66 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod; | 73 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod; |
... | @@ -1078,6 +1085,9 @@ public class TempJavaFragmentFiles { | ... | @@ -1078,6 +1085,9 @@ public class TempJavaFragmentFiles { |
1078 | if (!(parent instanceof JavaCodeGenerator)) { | 1085 | if (!(parent instanceof JavaCodeGenerator)) { |
1079 | throw new TranslatorException("missing parent node to contain current node info in generated file"); | 1086 | throw new TranslatorException("missing parent node to contain current node info in generated file"); |
1080 | } | 1087 | } |
1088 | + if (curNode instanceof YangJavaUses) { | ||
1089 | + curNode = ((YangJavaUses) curNode).getRefGroup(); | ||
1090 | + } | ||
1081 | JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInParent(curNode, | 1091 | JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInParent(curNode, |
1082 | parent, isList); | 1092 | parent, isList); |
1083 | if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) { | 1093 | if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) { |
... | @@ -1100,23 +1110,57 @@ public class TempJavaFragmentFiles { | ... | @@ -1100,23 +1110,57 @@ public class TempJavaFragmentFiles { |
1100 | */ | 1110 | */ |
1101 | public static JavaAttributeInfo getCurNodeAsAttributeInParent( | 1111 | public static JavaAttributeInfo getCurNodeAsAttributeInParent( |
1102 | YangNode curNode, YangNode parentNode, boolean isListNode) { | 1112 | YangNode curNode, YangNode parentNode, boolean isListNode) { |
1103 | - String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName(); | 1113 | + |
1104 | - /* | 1114 | + YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parentNode).getJavaFileInfo().getPluginConfig(); |
1105 | - * Get the import info corresponding to the attribute for import in | 1115 | + JavaFileInfo curNodeJavaInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
1106 | - * generated java files or qualified access | 1116 | + String curNodeName = null; |
1107 | - */ | 1117 | + |
1108 | - JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode, | 1118 | + if (curNodeJavaInfo.getJavaName() != null) { |
1109 | - getCapitalCase(curNodeName)); | 1119 | + curNodeName = curNodeJavaInfo.getJavaName(); |
1120 | + } else { | ||
1121 | + curNodeName = getCamelCase(curNode.getName(), pluginConfig.getConflictResolver()); | ||
1122 | + } | ||
1123 | + | ||
1110 | if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) { | 1124 | if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) { |
1111 | throw new TranslatorException("Parent node does not have file info"); | 1125 | throw new TranslatorException("Parent node does not have file info"); |
1112 | } | 1126 | } |
1127 | + | ||
1113 | TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(parentNode); | 1128 | TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(parentNode); |
1114 | boolean isQualified = true; | 1129 | boolean isQualified = true; |
1115 | JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData(); | 1130 | JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData(); |
1116 | if (isListNode) { | 1131 | if (isListNode) { |
1117 | parentImportData.setIfListImported(true); | 1132 | parentImportData.setIfListImported(true); |
1118 | } | 1133 | } |
1119 | - if (!detectCollisionBwParentAndChildForImport(curNode, qualifiedTypeInfo)) { | 1134 | + |
1135 | + /* | ||
1136 | + * Get the import info corresponding to the attribute for import in | ||
1137 | + * generated java files or qualified access | ||
1138 | + */ | ||
1139 | + | ||
1140 | + JavaQualifiedTypeInfo qualifiedTypeInfo = new JavaQualifiedTypeInfo(); | ||
1141 | + if (curNode instanceof YangJavaGrouping) { | ||
1142 | + qualifiedTypeInfo = resolveGroupingsQuailifiedInfo(curNode, pluginConfig); | ||
1143 | + } else { | ||
1144 | + qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode, | ||
1145 | + getCapitalCase(curNodeName)); | ||
1146 | + } | ||
1147 | + | ||
1148 | + if (parentNode instanceof YangJavaModule | ||
1149 | + || parentNode instanceof YangJavaSubModule | ||
1150 | + || parentNode instanceof YangJavaInput | ||
1151 | + || parentNode instanceof YangJavaOutput) { | ||
1152 | + parentImportData.addImportInfo(qualifiedTypeInfo); | ||
1153 | + isQualified = false; | ||
1154 | + } else if (curNode instanceof YangJavaGrouping) { | ||
1155 | + JavaFileInfo parentsClassInfo = ((JavaFileInfoContainer) parentNode).getJavaFileInfo(); | ||
1156 | + if (qualifiedTypeInfo.getClassInfo().equals(parentsClassInfo.getJavaName())) { | ||
1157 | + isQualified = true; | ||
1158 | + } | ||
1159 | + if (!qualifiedTypeInfo.getPkgInfo().equals(parentsClassInfo.getPackage())) { | ||
1160 | + parentImportData.addImportInfo(qualifiedTypeInfo); | ||
1161 | + isQualified = false; | ||
1162 | + } | ||
1163 | + } else if (!detectCollisionBwParentAndChildForImport(curNode, qualifiedTypeInfo)) { | ||
1120 | parentImportData.addImportInfo(qualifiedTypeInfo); | 1164 | parentImportData.addImportInfo(qualifiedTypeInfo); |
1121 | isQualified = false; | 1165 | isQualified = false; |
1122 | } | 1166 | } |
... | @@ -1124,6 +1168,63 @@ public class TempJavaFragmentFiles { | ... | @@ -1124,6 +1168,63 @@ public class TempJavaFragmentFiles { |
1124 | } | 1168 | } |
1125 | 1169 | ||
1126 | /** | 1170 | /** |
1171 | + * Resolves groupings java qualified info. | ||
1172 | + * | ||
1173 | + * @param curNode grouping node | ||
1174 | + * @param pluginConfig plugin configurations | ||
1175 | + * @return groupings java qualified info | ||
1176 | + */ | ||
1177 | + public static JavaQualifiedTypeInfo resolveGroupingsQuailifiedInfo(YangNode curNode, | ||
1178 | + YangPluginConfig pluginConfig) { | ||
1179 | + | ||
1180 | + JavaFileInfo groupingFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | ||
1181 | + JavaQualifiedTypeInfo qualifiedTypeInfo = new JavaQualifiedTypeInfo(); | ||
1182 | + if (groupingFileInfo.getPackage() == null) { | ||
1183 | + List<String> parentNames = new ArrayList<>(); | ||
1184 | + | ||
1185 | + YangNode tempNode = curNode.getParent(); | ||
1186 | + YangNode groupingSuperParent = null; | ||
1187 | + while (tempNode != null) { | ||
1188 | + parentNames.add(tempNode.getName()); | ||
1189 | + groupingSuperParent = tempNode; | ||
1190 | + tempNode = tempNode.getParent(); | ||
1191 | + } | ||
1192 | + | ||
1193 | + String pkg = null; | ||
1194 | + JavaFileInfo parentInfo = ((JavaFileInfoContainer) groupingSuperParent).getJavaFileInfo(); | ||
1195 | + if (parentInfo.getPackage() == null) { | ||
1196 | + if (groupingSuperParent instanceof YangJavaModule) { | ||
1197 | + YangJavaModule module = (YangJavaModule) groupingSuperParent; | ||
1198 | + String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module | ||
1199 | + .getRevision().getRevDate(), pluginConfig.getConflictResolver()); | ||
1200 | + pkg = modulePkg; | ||
1201 | + } else if (groupingSuperParent instanceof YangJavaSubModule) { | ||
1202 | + YangJavaSubModule submodule = (YangJavaSubModule) groupingSuperParent; | ||
1203 | + String subModulePkg = getRootPackage(submodule.getVersion(), | ||
1204 | + submodule.getNameSpaceFromModule(submodule.getBelongsTo()), | ||
1205 | + submodule.getRevision().getRevDate(), pluginConfig.getConflictResolver()); | ||
1206 | + pkg = subModulePkg; | ||
1207 | + } | ||
1208 | + } else { | ||
1209 | + pkg = parentInfo.getPackage(); | ||
1210 | + } | ||
1211 | + for (String name : parentNames) { | ||
1212 | + pkg = pkg + PERIOD + getCamelCase(name, pluginConfig.getConflictResolver()); | ||
1213 | + } | ||
1214 | + | ||
1215 | + qualifiedTypeInfo.setPkgInfo(pkg.toLowerCase()); | ||
1216 | + qualifiedTypeInfo.setClassInfo( | ||
1217 | + getCapitalCase(getCamelCase(curNode.getName(), pluginConfig.getConflictResolver()))); | ||
1218 | + return qualifiedTypeInfo; | ||
1219 | + | ||
1220 | + } else { | ||
1221 | + qualifiedTypeInfo.setPkgInfo(groupingFileInfo.getPackage().toLowerCase()); | ||
1222 | + qualifiedTypeInfo.setClassInfo(getCapitalCase(groupingFileInfo.getJavaName())); | ||
1223 | + return qualifiedTypeInfo; | ||
1224 | + } | ||
1225 | + } | ||
1226 | + | ||
1227 | + /** | ||
1127 | * Returns interface fragment files for node. | 1228 | * Returns interface fragment files for node. |
1128 | * | 1229 | * |
1129 | * @param node YANG node | 1230 | * @param node YANG node | ... | ... |
... | @@ -39,7 +39,10 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -39,7 +39,10 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
39 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; | 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; |
40 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; | 40 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; |
41 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; | 41 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; |
42 | +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaDataType; | ||
43 | +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportClass; | ||
42 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; | 44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; |
45 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getListAttribute; | ||
43 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile; | 46 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile; |
44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile; | 47 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile; |
45 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventSubjectFile; | 48 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventSubjectFile; |
... | @@ -48,6 +51,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato | ... | @@ -48,6 +51,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato |
48 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; | 51 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; |
49 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 52 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
50 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; | 53 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
54 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute; | ||
51 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 55 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
52 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; | 56 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; |
53 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod; | 57 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod; |
... | @@ -440,33 +444,129 @@ public class TempJavaServiceFragmentFiles | ... | @@ -440,33 +444,129 @@ public class TempJavaServiceFragmentFiles |
440 | String rpcName) throws IOException { | 444 | String rpcName) throws IOException { |
441 | String rpcInput = EMPTY_STRING; | 445 | String rpcInput = EMPTY_STRING; |
442 | String rpcOutput = VOID; | 446 | String rpcOutput = VOID; |
447 | + String rpcInputJavaDoc = EMPTY_STRING; | ||
443 | if (javaAttributeInfoOfInput != null) { | 448 | if (javaAttributeInfoOfInput != null) { |
444 | rpcInput = getCapitalCase(javaAttributeInfoOfInput.getAttributeName()); | 449 | rpcInput = getCapitalCase(javaAttributeInfoOfInput.getAttributeName()); |
445 | } | 450 | } |
446 | if (javaAttributeInfoOfOutput != null) { | 451 | if (javaAttributeInfoOfOutput != null) { |
447 | rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName()); | 452 | rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName()); |
448 | } | 453 | } |
454 | + if (!rpcInput.equals(EMPTY_STRING)) { | ||
455 | + rpcInputJavaDoc = RPC_INPUT_VAR_NAME; | ||
456 | + } | ||
457 | + appendToFile(getRpcInterfaceTempFileHandle(), | ||
458 | + generateJavaDocForRpc(rpcName, rpcInputJavaDoc, rpcOutput, pluginConfig) | ||
459 | + + getRpcServiceMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); | ||
460 | + appendToFile(getRpcImplTempFileHandle(), | ||
461 | + getRpcManagerMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); | ||
462 | + } | ||
463 | + | ||
464 | + /** | ||
465 | + * Adds rpc string information to applicable temp file. | ||
466 | + * | ||
467 | + * @param javaAttributeInfoOfInput rpc's input node attribute info | ||
468 | + * @param javaAttributeInfoOfOutput rpc's output node attribute info | ||
469 | + * @param rpcName name of the rpc function | ||
470 | + * @param pluginConfig plugin configurations | ||
471 | + * @param isInputLeafHolder if input node is leaf holder | ||
472 | + * @param isOutputLeafHolder if output node is leaf holder | ||
473 | + * @param isInputSingleChildHolder if input node is single child holder | ||
474 | + * @param isOutputSingleChildHolder if input node is single child holder | ||
475 | + * @throws IOException IO operation fail | ||
476 | + */ | ||
477 | + public void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, | ||
478 | + JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig, | ||
479 | + String rpcName, boolean isInputLeafHolder, boolean isOutputLeafHolder, | ||
480 | + boolean isInputSingleChildHolder, boolean isOutputSingleChildHolder) throws IOException { | ||
481 | + String rpcInput = EMPTY_STRING; | ||
482 | + String rpcOutput = VOID; | ||
483 | + String rpcInputJavaDoc = EMPTY_STRING; | ||
484 | + if (javaAttributeInfoOfInput != null) { | ||
485 | + rpcInput = getInputOutputNames(javaAttributeInfoOfInput, isInputLeafHolder, isInputSingleChildHolder, | ||
486 | + pluginConfig); | ||
487 | + } | ||
488 | + if (javaAttributeInfoOfOutput != null) { | ||
489 | + rpcOutput = | ||
490 | + getInputOutputNames(javaAttributeInfoOfOutput, isOutputLeafHolder, isOutputSingleChildHolder, | ||
491 | + pluginConfig); | ||
492 | + } | ||
493 | + if (!rpcInput.equals(EMPTY_STRING)) { | ||
494 | + rpcInputJavaDoc = RPC_INPUT_VAR_NAME; | ||
495 | + } | ||
496 | + | ||
449 | appendToFile(getRpcInterfaceTempFileHandle(), | 497 | appendToFile(getRpcInterfaceTempFileHandle(), |
450 | - generateJavaDocForRpc(rpcName, RPC_INPUT_VAR_NAME, rpcOutput, pluginConfig) | 498 | + generateJavaDocForRpc(rpcName, rpcInputJavaDoc, rpcOutput, pluginConfig) |
451 | + getRpcServiceMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); | 499 | + getRpcServiceMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); |
452 | appendToFile(getRpcImplTempFileHandle(), | 500 | appendToFile(getRpcImplTempFileHandle(), |
453 | getRpcManagerMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); | 501 | getRpcManagerMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE); |
454 | } | 502 | } |
455 | 503 | ||
456 | /** | 504 | /** |
505 | + * Returns names for input and output. | ||
506 | + * | ||
507 | + * @param attr attribute info | ||
508 | + * @param isLeafHolder if leaf holder | ||
509 | + * @param isSinglechildHolder if single child holder | ||
510 | + * @param pluginConfig plugin configurations | ||
511 | + * @return names for input and output | ||
512 | + */ | ||
513 | + private String getInputOutputNames(JavaAttributeInfo attr, boolean isLeafHolder, boolean isSinglechildHolder, | ||
514 | + YangPluginConfig pluginConfig) { | ||
515 | + if (!attr.isListAttr()) { | ||
516 | + if (!isLeafHolder || isSinglechildHolder) { | ||
517 | + String attrName = ""; | ||
518 | + if (!attr.isQualifiedName()) { | ||
519 | + attrName = getCapitalCase(attr.getAttributeName()); | ||
520 | + } else { | ||
521 | + attrName = attr.getImportInfo().getPkgInfo() + "." + getCapitalCase(attr.getAttributeName()); | ||
522 | + } | ||
523 | + return attrName; | ||
524 | + } else { | ||
525 | + String rpcInput = getJavaImportClass(attr.getAttributeType(), false, | ||
526 | + pluginConfig.getConflictResolver()); | ||
527 | + if (rpcInput == null) { | ||
528 | + rpcInput = getJavaDataType(attr.getAttributeType()); | ||
529 | + } | ||
530 | + return rpcInput; | ||
531 | + } | ||
532 | + } else { | ||
533 | + if (!isLeafHolder || isSinglechildHolder) { | ||
534 | + String attrName = ""; | ||
535 | + if (!attr.isQualifiedName()) { | ||
536 | + attrName = getCapitalCase(attr.getAttributeName()); | ||
537 | + } else { | ||
538 | + attrName = attr.getImportInfo().getPkgInfo() + "." + getCapitalCase(attr.getAttributeName()); | ||
539 | + } | ||
540 | + return getListAttribute(attrName); | ||
541 | + | ||
542 | + } else { | ||
543 | + return getListAttribute(getJavaImportClass(attr.getAttributeType(), true, | ||
544 | + pluginConfig.getConflictResolver())); | ||
545 | + | ||
546 | + } | ||
547 | + } | ||
548 | + } | ||
549 | + | ||
550 | + /** | ||
457 | * Adds the JAVA rpc snippet information. | 551 | * Adds the JAVA rpc snippet information. |
458 | * | 552 | * |
459 | * @param javaAttributeInfoOfInput rpc's input node attribute info | 553 | * @param javaAttributeInfoOfInput rpc's input node attribute info |
460 | * @param javaAttributeInfoOfOutput rpc's output node attribute info | 554 | * @param javaAttributeInfoOfOutput rpc's output node attribute info |
461 | * @param pluginConfig plugin configurations | 555 | * @param pluginConfig plugin configurations |
462 | * @param rpcName name of the rpc function | 556 | * @param rpcName name of the rpc function |
557 | + * @param isInputLeafHolder if input node is leaf holder | ||
558 | + * @param isOutputLeafHolder if output node is leaf holder | ||
559 | + * @param isInputSingleChildHolder if input node is single child holder | ||
560 | + * @param isOutputSingleChildHolder if input node is single child holder | ||
463 | * @throws IOException IO operation fail | 561 | * @throws IOException IO operation fail |
464 | */ | 562 | */ |
465 | public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput, | 563 | public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput, |
466 | JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig, | 564 | JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig, |
467 | - String rpcName) | 565 | + String rpcName, boolean isInputLeafHolder, boolean isOutputLeafHolder, |
566 | + boolean isInputSingleChildHolder, boolean isOutputSingleChildHolder) | ||
468 | throws IOException { | 567 | throws IOException { |
469 | - addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, pluginConfig, rpcName); | 568 | + addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, pluginConfig, rpcName, isInputLeafHolder, |
569 | + isOutputLeafHolder, isInputSingleChildHolder, isOutputSingleChildHolder); | ||
470 | } | 570 | } |
471 | 571 | ||
472 | /** | 572 | /** |
... | @@ -690,6 +790,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -690,6 +790,7 @@ public class TempJavaServiceFragmentFiles |
690 | 790 | ||
691 | String currentInfo = getCapitalCase(getCamelCase(((YangNotification) curNode).getName(), | 791 | String currentInfo = getCapitalCase(getCamelCase(((YangNotification) curNode).getName(), |
692 | pluginConfig.getConflictResolver())); | 792 | pluginConfig.getConflictResolver())); |
793 | + String notificationName = ((YangNotification) curNode).getName(); | ||
693 | 794 | ||
694 | JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode.getParent(), | 795 | JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode.getParent(), |
695 | getCapitalCase(currentInfo)); | 796 | getCapitalCase(currentInfo)); |
... | @@ -699,7 +800,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -699,7 +800,7 @@ public class TempJavaServiceFragmentFiles |
699 | null, false, false); | 800 | null, false, false); |
700 | 801 | ||
701 | /*Adds java info for event in respective temp files.*/ | 802 | /*Adds java info for event in respective temp files.*/ |
702 | - addEventEnum(currentInfo, pluginConfig); | 803 | + addEventEnum(notificationName, pluginConfig); |
703 | addEventSubjectAttribute(javaAttributeInfo, pluginConfig); | 804 | addEventSubjectAttribute(javaAttributeInfo, pluginConfig); |
704 | addEventSubjectGetter(javaAttributeInfo, pluginConfig); | 805 | addEventSubjectGetter(javaAttributeInfo, pluginConfig); |
705 | addEventSubjectSetter(javaAttributeInfo, pluginConfig, currentInfo); | 806 | addEventSubjectSetter(javaAttributeInfo, pluginConfig, currentInfo); |
... | @@ -709,7 +810,7 @@ public class TempJavaServiceFragmentFiles | ... | @@ -709,7 +810,7 @@ public class TempJavaServiceFragmentFiles |
709 | private void addEventEnum(String notificationName, YangPluginConfig pluginConfig) throws IOException { | 810 | private void addEventEnum(String notificationName, YangPluginConfig pluginConfig) throws IOException { |
710 | appendToFile(getEventEnumTempFileHandle(), | 811 | appendToFile(getEventEnumTempFileHandle(), |
711 | getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig) + FOUR_SPACE_INDENTATION | 812 | getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig) + FOUR_SPACE_INDENTATION |
712 | - + notificationName.toUpperCase() + COMMA + NEW_LINE); | 813 | + + getEnumJavaAttribute(notificationName).toUpperCase() + COMMA + NEW_LINE); |
713 | } | 814 | } |
714 | 815 | ||
715 | /*Adds event method in event class*/ | 816 | /*Adds event method in event class*/ | ... | ... |
... | @@ -15,18 +15,116 @@ | ... | @@ -15,18 +15,116 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | +import java.io.IOException; | ||
19 | + | ||
18 | import org.onosproject.yangutils.datamodel.YangGrouping; | 20 | import org.onosproject.yangutils.datamodel.YangGrouping; |
21 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
22 | +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | ||
23 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ||
24 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
25 | +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | ||
26 | + | ||
27 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | ||
28 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; | ||
19 | 29 | ||
20 | /** | 30 | /** |
21 | * Represents grouping information extended to support java code generation. | 31 | * Represents grouping information extended to support java code generation. |
22 | */ | 32 | */ |
23 | public class YangJavaGrouping | 33 | public class YangJavaGrouping |
24 | - extends YangGrouping { | 34 | + extends YangGrouping implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
35 | + | ||
36 | + /** | ||
37 | + * Contains the information of the java file being generated. | ||
38 | + */ | ||
39 | + private JavaFileInfo javaFileInfo; | ||
40 | + | ||
41 | + /** | ||
42 | + * File handle to maintain temporary java code fragments as per the code | ||
43 | + * snippet types. | ||
44 | + */ | ||
45 | + private TempJavaCodeFragmentFiles tempFileHandle; | ||
25 | 46 | ||
26 | /** | 47 | /** |
27 | * Creates YANG Java grouping object. | 48 | * Creates YANG Java grouping object. |
28 | */ | 49 | */ |
29 | public YangJavaGrouping() { | 50 | public YangJavaGrouping() { |
30 | super(); | 51 | super(); |
52 | + setJavaFileInfo(new JavaFileInfo()); | ||
53 | + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER); | ||
31 | } | 54 | } |
55 | + | ||
56 | + /** | ||
57 | + * Returns the generated java file information. | ||
58 | + * | ||
59 | + * @return generated java file information | ||
60 | + */ | ||
61 | + @Override | ||
62 | + public JavaFileInfo getJavaFileInfo() { | ||
63 | + if (javaFileInfo == null) { | ||
64 | + throw new TranslatorException("Missing java info in java datamodel node"); | ||
65 | + } | ||
66 | + return javaFileInfo; | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * Sets the java file info object. | ||
71 | + * | ||
72 | + * @param javaInfo java file info object | ||
73 | + */ | ||
74 | + @Override | ||
75 | + public void setJavaFileInfo(JavaFileInfo javaInfo) { | ||
76 | + javaFileInfo = javaInfo; | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * Returns the temporary file handle. | ||
81 | + * | ||
82 | + * @return temporary file handle | ||
83 | + */ | ||
84 | + @Override | ||
85 | + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | ||
86 | + return tempFileHandle; | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * Sets temporary file handle. | ||
91 | + * | ||
92 | + * @param fileHandle temporary file handle | ||
93 | + */ | ||
94 | + @Override | ||
95 | + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | ||
96 | + tempFileHandle = fileHandle; | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Prepare the information for java code generation corresponding to YANG | ||
101 | + * grouping info. | ||
102 | + * | ||
103 | + * @param yangPlugin YANG plugin config | ||
104 | + * @throws TranslatorException translator operation fail | ||
105 | + */ | ||
106 | + @Override | ||
107 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { | ||
108 | + try { | ||
109 | + generateCodeOfNode(this, yangPlugin); | ||
110 | + } catch (IOException e) { | ||
111 | + throw new TranslatorException( | ||
112 | + "Failed to prepare generate code entry for container node " + this.getName()); | ||
113 | + } | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * Create a java file using the YANG grouping info. | ||
118 | + * | ||
119 | + * @throws TranslatorException translator operation fail | ||
120 | + */ | ||
121 | + @Override | ||
122 | + public void generateCodeExit() throws TranslatorException { | ||
123 | + try { | ||
124 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | ||
125 | + } catch (IOException e) { | ||
126 | + throw new TranslatorException("Failed to generate code for container node " + this.getName()); | ||
127 | + } | ||
128 | + } | ||
129 | + | ||
32 | } | 130 | } | ... | ... |
... | @@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ... | @@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
26 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 26 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
27 | 27 | ||
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
29 | -import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; | 29 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * Represents input information extended to support java code generation. | 32 | * Represents input information extended to support java code generation. |
... | @@ -46,6 +46,8 @@ public class YangJavaInput | ... | @@ -46,6 +46,8 @@ public class YangJavaInput |
46 | */ | 46 | */ |
47 | private TempJavaCodeFragmentFiles tempFileHandle; | 47 | private TempJavaCodeFragmentFiles tempFileHandle; |
48 | 48 | ||
49 | + private boolean codeGenFlag; | ||
50 | + | ||
49 | /** | 51 | /** |
50 | * Creates an instance of java input. | 52 | * Creates an instance of java input. |
51 | */ | 53 | */ |
... | @@ -108,7 +110,7 @@ public class YangJavaInput | ... | @@ -108,7 +110,7 @@ public class YangJavaInput |
108 | @Override | 110 | @Override |
109 | public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { | 111 | public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
110 | try { | 112 | try { |
111 | - generateCodeOfNode(this, yangPlugin); | 113 | + generateCodeOfAugmentableNode(this, yangPlugin); |
112 | } catch (IOException e) { | 114 | } catch (IOException e) { |
113 | throw new TranslatorException( | 115 | throw new TranslatorException( |
114 | "Failed to prepare generate code entry for input node " + this.getName()); | 116 | "Failed to prepare generate code entry for input node " + this.getName()); |
... | @@ -123,9 +125,29 @@ public class YangJavaInput | ... | @@ -123,9 +125,29 @@ public class YangJavaInput |
123 | @Override | 125 | @Override |
124 | public void generateCodeExit() throws TranslatorException { | 126 | public void generateCodeExit() throws TranslatorException { |
125 | try { | 127 | try { |
126 | - getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 128 | + if (isCodeGenFlag()) { |
129 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | ||
130 | + } | ||
127 | } catch (IOException e) { | 131 | } catch (IOException e) { |
128 | throw new TranslatorException("Failed to generate code for input node " + this.getName()); | 132 | throw new TranslatorException("Failed to generate code for input node " + this.getName()); |
129 | } | 133 | } |
130 | } | 134 | } |
135 | + | ||
136 | + /** | ||
137 | + * Returns code generator flag. | ||
138 | + * | ||
139 | + * @return code generator flag | ||
140 | + */ | ||
141 | + public boolean isCodeGenFlag() { | ||
142 | + return codeGenFlag; | ||
143 | + } | ||
144 | + | ||
145 | + /** | ||
146 | + * Sets code generator flag. | ||
147 | + * | ||
148 | + * @param codeGenFlag code generator flag | ||
149 | + */ | ||
150 | + public void setCodeGenFlag(boolean codeGenFlag) { | ||
151 | + this.codeGenFlag = codeGenFlag; | ||
152 | + } | ||
131 | } | 153 | } | ... | ... |
... | @@ -71,6 +71,7 @@ public class YangJavaLeaf | ... | @@ -71,6 +71,7 @@ public class YangJavaLeaf |
71 | * | 71 | * |
72 | * @return java naming conflict resolve configurations | 72 | * @return java naming conflict resolve configurations |
73 | */ | 73 | */ |
74 | + @Override | ||
74 | public YangToJavaNamingConflictUtil getConflictResolveConfig() { | 75 | public YangToJavaNamingConflictUtil getConflictResolveConfig() { |
75 | return conflictResolveConfig; | 76 | return conflictResolveConfig; |
76 | } | 77 | } |
... | @@ -80,6 +81,7 @@ public class YangJavaLeaf | ... | @@ -80,6 +81,7 @@ public class YangJavaLeaf |
80 | * | 81 | * |
81 | * @param conflictResolveConfig java naming conflict resolve configurations | 82 | * @param conflictResolveConfig java naming conflict resolve configurations |
82 | */ | 83 | */ |
84 | + @Override | ||
83 | public void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig) { | 85 | public void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig) { |
84 | this.conflictResolveConfig = conflictResolveConfig; | 86 | this.conflictResolveConfig = conflictResolveConfig; |
85 | } | 87 | } | ... | ... |
... | @@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ... | @@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
26 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 26 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
27 | 27 | ||
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
29 | -import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; | 29 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * Represents output information extended to support java code generation. | 32 | * Represents output information extended to support java code generation. |
... | @@ -46,6 +46,8 @@ public class YangJavaOutput | ... | @@ -46,6 +46,8 @@ public class YangJavaOutput |
46 | */ | 46 | */ |
47 | private TempJavaCodeFragmentFiles tempFileHandle; | 47 | private TempJavaCodeFragmentFiles tempFileHandle; |
48 | 48 | ||
49 | + private boolean codeGenFlag; | ||
50 | + | ||
49 | /** | 51 | /** |
50 | * Creates an instance of java output. | 52 | * Creates an instance of java output. |
51 | */ | 53 | */ |
... | @@ -108,7 +110,7 @@ public class YangJavaOutput | ... | @@ -108,7 +110,7 @@ public class YangJavaOutput |
108 | @Override | 110 | @Override |
109 | public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { | 111 | public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
110 | try { | 112 | try { |
111 | - generateCodeOfNode(this, yangPlugin); | 113 | + generateCodeOfAugmentableNode(this, yangPlugin); |
112 | } catch (IOException e) { | 114 | } catch (IOException e) { |
113 | throw new TranslatorException( | 115 | throw new TranslatorException( |
114 | "Failed to prepare generate code entry for output node " + this.getName()); | 116 | "Failed to prepare generate code entry for output node " + this.getName()); |
... | @@ -124,10 +126,30 @@ public class YangJavaOutput | ... | @@ -124,10 +126,30 @@ public class YangJavaOutput |
124 | @Override | 126 | @Override |
125 | public void generateCodeExit() throws TranslatorException { | 127 | public void generateCodeExit() throws TranslatorException { |
126 | try { | 128 | try { |
127 | - getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | 129 | + if (isCodeGenFlag()) { |
130 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); | ||
131 | + } | ||
128 | } catch (IOException e) { | 132 | } catch (IOException e) { |
129 | throw new TranslatorException( | 133 | throw new TranslatorException( |
130 | "Failed to prepare generate code exit for output node " + this.getName()); | 134 | "Failed to prepare generate code exit for output node " + this.getName()); |
131 | } | 135 | } |
132 | } | 136 | } |
137 | + | ||
138 | + /** | ||
139 | + * Returns code generator flag. | ||
140 | + * | ||
141 | + * @return code generator flag | ||
142 | + */ | ||
143 | + public boolean isCodeGenFlag() { | ||
144 | + return codeGenFlag; | ||
145 | + } | ||
146 | + | ||
147 | + /** | ||
148 | + * Sets code generator flag. | ||
149 | + * | ||
150 | + * @param codeGenFlag code generator flag | ||
151 | + */ | ||
152 | + public void setCodeGenFlag(boolean codeGenFlag) { | ||
153 | + this.codeGenFlag = codeGenFlag; | ||
154 | + } | ||
133 | } | 155 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
This diff is collapsed. Click to expand it.
... | @@ -55,7 +55,7 @@ public class YangJavaType<T> | ... | @@ -55,7 +55,7 @@ public class YangJavaType<T> |
55 | */ | 55 | */ |
56 | importInfo.setClassInfo(className); | 56 | importInfo.setClassInfo(className); |
57 | String classPkg = AttributesJavaDataType.getJavaImportPackage(this, | 57 | String classPkg = AttributesJavaDataType.getJavaImportPackage(this, |
58 | - false, className, conflictResolver); | 58 | + false, conflictResolver); |
59 | if (classPkg == null) { | 59 | if (classPkg == null) { |
60 | throw new TranslatorException("import package cannot be null when the class is used"); | 60 | throw new TranslatorException("import package cannot be null when the class is used"); |
61 | } | 61 | } | ... | ... |
... | @@ -15,18 +15,113 @@ | ... | @@ -15,18 +15,113 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.yangutils.translator.tojava.javamodel; | 16 | package org.onosproject.yangutils.translator.tojava.javamodel; |
17 | 17 | ||
18 | +import java.io.IOException; | ||
19 | + | ||
18 | import org.onosproject.yangutils.datamodel.YangUses; | 20 | import org.onosproject.yangutils.datamodel.YangUses; |
21 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
22 | +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | ||
23 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ||
24 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
25 | +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | ||
26 | + | ||
27 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | ||
28 | +import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile; | ||
19 | 29 | ||
20 | /** | 30 | /** |
21 | * Represents uses information extended to support java code generation. | 31 | * Represents uses information extended to support java code generation. |
22 | */ | 32 | */ |
23 | public class YangJavaUses | 33 | public class YangJavaUses |
24 | - extends YangUses { | 34 | + extends YangUses implements JavaCodeGeneratorInfo, JavaCodeGenerator { |
35 | + | ||
36 | + | ||
37 | + /** | ||
38 | + * Contains the information of the java file being generated. | ||
39 | + */ | ||
40 | + private JavaFileInfo javaFileInfo; | ||
41 | + | ||
42 | + /** | ||
43 | + * File handle to maintain temporary java code fragments as per the code | ||
44 | + * snippet types. | ||
45 | + */ | ||
46 | + private TempJavaCodeFragmentFiles tempFileHandle; | ||
25 | 47 | ||
26 | /** | 48 | /** |
27 | * Creates YANG java uses object. | 49 | * Creates YANG java uses object. |
28 | */ | 50 | */ |
29 | public YangJavaUses() { | 51 | public YangJavaUses() { |
30 | super(); | 52 | super(); |
53 | + setJavaFileInfo(new JavaFileInfo()); | ||
54 | + getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER); | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Returns the generated java file information. | ||
59 | + * | ||
60 | + * @return generated java file information | ||
61 | + */ | ||
62 | + @Override | ||
63 | + public JavaFileInfo getJavaFileInfo() { | ||
64 | + if (javaFileInfo == null) { | ||
65 | + throw new TranslatorException("Missing java info in java datamodel node"); | ||
66 | + } | ||
67 | + return javaFileInfo; | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Sets the java file info object. | ||
72 | + * | ||
73 | + * @param javaInfo java file info object | ||
74 | + */ | ||
75 | + @Override | ||
76 | + public void setJavaFileInfo(JavaFileInfo javaInfo) { | ||
77 | + javaFileInfo = javaInfo; | ||
31 | } | 78 | } |
79 | + | ||
80 | + /** | ||
81 | + * Returns the temporary file handle. | ||
82 | + * | ||
83 | + * @return temporary file handle | ||
84 | + */ | ||
85 | + @Override | ||
86 | + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | ||
87 | + return tempFileHandle; | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * Sets temporary file handle. | ||
92 | + * | ||
93 | + * @param fileHandle temporary file handle | ||
94 | + */ | ||
95 | + @Override | ||
96 | + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | ||
97 | + tempFileHandle = fileHandle; | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * Prepare the information for java code generation corresponding to YANG | ||
102 | + * uses info. | ||
103 | + * | ||
104 | + * @param yangPlugin YANG plugin config | ||
105 | + * @throws TranslatorException translator operation fail | ||
106 | + */ | ||
107 | + @Override | ||
108 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { | ||
109 | + try { | ||
110 | + addCurNodeInfoInParentTempFile(this, false, yangPlugin); | ||
111 | + } catch (IOException e) { | ||
112 | + throw new TranslatorException( | ||
113 | + "Failed to prepare generate code entry for container node " + this.getName()); | ||
114 | + } | ||
115 | + } | ||
116 | + | ||
117 | + /** | ||
118 | + * Create a java file using the YANG uses info. | ||
119 | + * | ||
120 | + * @throws TranslatorException translator operation fail | ||
121 | + */ | ||
122 | + @Override | ||
123 | + public void generateCodeExit() throws TranslatorException { | ||
124 | + // no code generation will be done for uses. | ||
125 | + } | ||
126 | + | ||
32 | } | 127 | } | ... | ... |
... | @@ -270,11 +270,10 @@ public final class AttributesJavaDataType { | ... | @@ -270,11 +270,10 @@ public final class AttributesJavaDataType { |
270 | * | 270 | * |
271 | * @param yangType YANG type | 271 | * @param yangType YANG type |
272 | * @param isListAttr if the attribute is of list type | 272 | * @param isListAttr if the attribute is of list type |
273 | - * @param classInfo java import class info | ||
274 | * @param conflictResolver object of YANG to java naming conflict util | 273 | * @param conflictResolver object of YANG to java naming conflict util |
275 | * @return java import package | 274 | * @return java import package |
276 | */ | 275 | */ |
277 | - public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo, | 276 | + public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, |
278 | YangToJavaNamingConflictUtil conflictResolver) { | 277 | YangToJavaNamingConflictUtil conflictResolver) { |
279 | 278 | ||
280 | YangDataTypes type = yangType.getDataType(); | 279 | YangDataTypes type = yangType.getDataType(); |
... | @@ -430,13 +429,13 @@ public final class AttributesJavaDataType { | ... | @@ -430,13 +429,13 @@ public final class AttributesJavaDataType { |
430 | YangJavaModule module = (YangJavaModule) parent; | 429 | YangJavaModule module = (YangJavaModule) parent; |
431 | String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module | 430 | String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module |
432 | .getRevision().getRevDate(), conflictResolver); | 431 | .getRevision().getRevDate(), conflictResolver); |
433 | - return modulePkg + PERIOD + getCamelCase(module.getName(), null).toLowerCase(); | 432 | + return modulePkg + PERIOD + getCamelCase(module.getName(), conflictResolver).toLowerCase(); |
434 | } else if (parent instanceof YangJavaSubModule) { | 433 | } else if (parent instanceof YangJavaSubModule) { |
435 | YangJavaSubModule submodule = (YangJavaSubModule) parent; | 434 | YangJavaSubModule submodule = (YangJavaSubModule) parent; |
436 | String subModulePkg = getRootPackage(submodule.getVersion(), | 435 | String subModulePkg = getRootPackage(submodule.getVersion(), |
437 | submodule.getNameSpaceFromModule(submodule.getBelongsTo()), | 436 | submodule.getNameSpaceFromModule(submodule.getBelongsTo()), |
438 | submodule.getRevision().getRevDate(), conflictResolver); | 437 | submodule.getRevision().getRevDate(), conflictResolver); |
439 | - return subModulePkg + PERIOD + getCamelCase(submodule.getName(), null).toLowerCase(); | 438 | + return subModulePkg + PERIOD + getCamelCase(submodule.getName(), conflictResolver).toLowerCase(); |
440 | } | 439 | } |
441 | } | 440 | } |
442 | return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase(); | 441 | return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase(); | ... | ... |
... | @@ -115,7 +115,7 @@ public final class JavaCodeSnippetGen { | ... | @@ -115,7 +115,7 @@ public final class JavaCodeSnippetGen { |
115 | * @param type attribute type | 115 | * @param type attribute type |
116 | * @return list attribute string | 116 | * @return list attribute string |
117 | */ | 117 | */ |
118 | - private static String getListAttribute(String type) { | 118 | + public static String getListAttribute(String type) { |
119 | return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET; | 119 | return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET; |
120 | } | 120 | } |
121 | 121 | ... | ... |
... | @@ -366,7 +366,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -366,7 +366,7 @@ public final class JavaIdentifierSyntax { |
366 | i = 1; | 366 | i = 1; |
367 | } | 367 | } |
368 | for (; i < stringArray.length; i++) { | 368 | for (; i < stringArray.length; i++) { |
369 | - if ((i + 1) == stringArray.length) { | 369 | + if (i + 1 == stringArray.length) { |
370 | if (stringArray[i].matches(REGEX_FOR_SINGLE_LETTER) | 370 | if (stringArray[i].matches(REGEX_FOR_SINGLE_LETTER) |
371 | || stringArray[i].matches(REGEX_FOR_DIGITS_WITH_SINGLE_LETTER)) { | 371 | || stringArray[i].matches(REGEX_FOR_DIGITS_WITH_SINGLE_LETTER)) { |
372 | ruleChecker = ruleChecker + stringArray[i].toLowerCase(); | 372 | ruleChecker = ruleChecker + stringArray[i].toLowerCase(); | ... | ... |
... | @@ -265,7 +265,7 @@ public final class MethodsGenerator { | ... | @@ -265,7 +265,7 @@ public final class MethodsGenerator { |
265 | * @return getter for attribute | 265 | * @return getter for attribute |
266 | */ | 266 | */ |
267 | public static String getGetter(String type, String name, int generatedJavaFiles) { | 267 | public static String getGetter(String type, String name, int generatedJavaFiles) { |
268 | - String ret = parseTypeForGetter(type); | 268 | + String ret = parseTypeForReturnValue(type); |
269 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { | 269 | if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) { |
270 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name) | 270 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name) |
271 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + | 271 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + |
... | @@ -281,7 +281,7 @@ public final class MethodsGenerator { | ... | @@ -281,7 +281,7 @@ public final class MethodsGenerator { |
281 | } | 281 | } |
282 | 282 | ||
283 | /*Provides string to return for type.*/ | 283 | /*Provides string to return for type.*/ |
284 | - private static String parseTypeForGetter(String type) { | 284 | + private static String parseTypeForReturnValue(String type) { |
285 | switch (type) { | 285 | switch (type) { |
286 | case BYTE: | 286 | case BYTE: |
287 | case INT: | 287 | case INT: |
... | @@ -555,12 +555,11 @@ public final class MethodsGenerator { | ... | @@ -555,12 +555,11 @@ public final class MethodsGenerator { |
555 | YangPluginConfig pluginConfig) { | 555 | YangPluginConfig pluginConfig) { |
556 | 556 | ||
557 | rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver()); | 557 | rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver()); |
558 | - inputName = getCapitalCase(inputName); | 558 | + if (!inputName.equals(EMPTY_STRING)) { |
559 | - if (!outputName.equals(VOID)) { | 559 | + inputName = inputName + SPACE + RPC_INPUT_VAR_NAME; |
560 | - outputName = getCapitalCase(outputName); | ||
561 | } | 560 | } |
562 | - return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName + SPACE | 561 | + return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName |
563 | - + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SEMI_COLAN; | 562 | + + CLOSE_PARENTHESIS + SEMI_COLAN; |
564 | } | 563 | } |
565 | 564 | ||
566 | /** | 565 | /** |
... | @@ -576,16 +575,17 @@ public final class MethodsGenerator { | ... | @@ -576,16 +575,17 @@ public final class MethodsGenerator { |
576 | YangPluginConfig pluginConfig) { | 575 | YangPluginConfig pluginConfig) { |
577 | 576 | ||
578 | rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver()); | 577 | rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver()); |
579 | - inputName = getCapitalCase(inputName); | 578 | + if (!inputName.equals(EMPTY_STRING)) { |
580 | - if (!outputName.equals(VOID)) { | 579 | + inputName = inputName + SPACE + RPC_INPUT_VAR_NAME; |
581 | - outputName = getCapitalCase(outputName); | ||
582 | } | 580 | } |
583 | 581 | ||
584 | - String method = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName | 582 | + String method = |
585 | - + OPEN_PARENTHESIS + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE | 583 | + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName |
586 | - + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE; | 584 | + + OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SPACE |
585 | + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE; | ||
587 | if (!outputName.contentEquals(VOID)) { | 586 | if (!outputName.contentEquals(VOID)) { |
588 | - method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE; | 587 | + method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + parseTypeForReturnValue(outputName) + SEMI_COLAN |
588 | + + NEW_LINE; | ||
589 | } | 589 | } |
590 | method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | 590 | method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
591 | 591 | ... | ... |
... | @@ -29,7 +29,10 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ... | @@ -29,7 +29,10 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
29 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; | 29 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; |
30 | import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles; | 30 | import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles; |
31 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; | 31 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; |
32 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput; | ||
32 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; | 33 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; |
34 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput; | ||
35 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule; | ||
33 | 36 | ||
34 | import static java.util.Collections.sort; | 37 | import static java.util.Collections.sort; |
35 | 38 | ||
... | @@ -339,6 +342,12 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -339,6 +342,12 @@ public final class TempJavaCodeFragmentFilesUtils { |
339 | JavaQualifiedTypeInfo qualifiedTypeInfo) { | 342 | JavaQualifiedTypeInfo qualifiedTypeInfo) { |
340 | 343 | ||
341 | YangNode parent = curNode.getParent(); | 344 | YangNode parent = curNode.getParent(); |
345 | + if (parent instanceof YangJavaModule | ||
346 | + || parent instanceof YangJavaSubModule | ||
347 | + || parent instanceof YangJavaInput | ||
348 | + || parent instanceof YangJavaOutput) { | ||
349 | + return false; | ||
350 | + } | ||
342 | String parentsClassInfo = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()); | 351 | String parentsClassInfo = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()); |
343 | String childsClassInfo = qualifiedTypeInfo.getClassInfo(); | 352 | String childsClassInfo = qualifiedTypeInfo.getClassInfo(); |
344 | if (childsClassInfo.equals(parentsClassInfo)) { | 353 | if (childsClassInfo.equals(parentsClassInfo)) { | ... | ... |
... | @@ -24,6 +24,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | ... | @@ -24,6 +24,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
24 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; | 24 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; |
25 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; | 25 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; |
26 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT; | 26 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT; |
27 | +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | ||
27 | import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC; | 28 | import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC; |
28 | import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC; | 29 | import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC; |
29 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_JAVA_DOC; | 30 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_JAVA_DOC; |
... | @@ -298,8 +299,10 @@ public final class JavaDocGen { | ... | @@ -298,8 +299,10 @@ public final class JavaDocGen { |
298 | 299 | ||
299 | String javadoc = | 300 | String javadoc = |
300 | NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC | 301 | NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC |
301 | - + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK | 302 | + + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK; |
302 | - + getInputString(inputName, rpcName); | 303 | + if (!inputName.equals(EMPTY_STRING)) { |
304 | + javadoc = javadoc + getInputString(inputName, rpcName); | ||
305 | + } | ||
303 | if (!outputName.equals(VOID)) { | 306 | if (!outputName.equals(VOID)) { |
304 | javadoc = javadoc + getOutputString(outputName, rpcName); | 307 | javadoc = javadoc + getOutputString(outputName, rpcName); |
305 | } | 308 | } |
... | @@ -406,7 +409,8 @@ public final class JavaDocGen { | ... | @@ -406,7 +409,8 @@ public final class JavaDocGen { |
406 | } else { | 409 | } else { |
407 | setter = setter + VALUE + SPACE + OF + SPACE; | 410 | setter = setter + VALUE + SPACE + OF + SPACE; |
408 | } | 411 | } |
409 | - setter = setter + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + BUILDER_OBJECT + attribute | 412 | + setter = setter + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + BUILDER_OBJECT |
413 | + + attribute | ||
410 | + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; | 414 | + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
411 | return setter; | 415 | return setter; |
412 | } | 416 | } | ... | ... |
... | @@ -433,7 +433,20 @@ public final class YangIoUtils { | ... | @@ -433,7 +433,20 @@ public final class YangIoUtils { |
433 | } else { | 433 | } else { |
434 | stringBuilder.append(line + NEW_LINE); | 434 | stringBuilder.append(line + NEW_LINE); |
435 | } | 435 | } |
436 | - return stringBuilder.toString(); | 436 | + |
437 | + String[] strArray = stringBuilder.toString().split(NEW_LINE); | ||
438 | + StringBuilder tempBuilder = new StringBuilder(); | ||
439 | + for (String str : strArray) { | ||
440 | + if (str.length() > SUB_LINE_SIZE) { | ||
441 | + if (str.contains(SPACE)) { | ||
442 | + String[] strArr = str.split(SPACE); | ||
443 | + tempBuilder = updateString(strArr, tempBuilder, SPACE, SUB_LINE_SIZE); | ||
444 | + } | ||
445 | + } else { | ||
446 | + tempBuilder.append(str + NEW_LINE); | ||
447 | + } | ||
448 | + } | ||
449 | + return tempBuilder.toString(); | ||
437 | } | 450 | } |
438 | 451 | ||
439 | /*Updates the given line with the given size conditions.*/ | 452 | /*Updates the given line with the given size conditions.*/ | ... | ... |
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.parser.parseutils; | ||
18 | - | ||
19 | -import org.junit.Test; | ||
20 | - | ||
21 | -import static org.hamcrest.core.Is.is; | ||
22 | -import static org.junit.Assert.assertThat; | ||
23 | -import static org.onosproject.yangutils.utils.YangConstructType.CONTACT_DATA; | ||
24 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | ||
25 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | ||
26 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | ||
27 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | ||
28 | - | ||
29 | -/** | ||
30 | - * Test case for testing listener error message construction util. | ||
31 | - */ | ||
32 | -public class ListenerErrorMessageConstructionTest { | ||
33 | - | ||
34 | - /** | ||
35 | - * Checks for error message construction with parsable data type name. | ||
36 | - */ | ||
37 | - @Test | ||
38 | - public void checkErrorMsgConstructionWithName() { | ||
39 | - | ||
40 | - // Create an test error message | ||
41 | - String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY); | ||
42 | - | ||
43 | - // Check message. | ||
44 | - assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact " | ||
45 | - + "\"Test Instance\" before processing.")); | ||
46 | - } | ||
47 | - | ||
48 | - /** | ||
49 | - * Checks for error message construction without parsable data type name. | ||
50 | - */ | ||
51 | - @Test | ||
52 | - public void checkErrorMsgConstructionWithoutName() { | ||
53 | - | ||
54 | - // Create an test error message | ||
55 | - String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY); | ||
56 | - | ||
57 | - // Check message. | ||
58 | - assertThat(testErrorMessage, | ||
59 | - is("Internal parser error detected: Invalid holder for contact \"Test Instance\"" | ||
60 | - + " before processing.")); | ||
61 | - } | ||
62 | - | ||
63 | - /** | ||
64 | - * Checks for extended error message construction with parsable data type | ||
65 | - * name. | ||
66 | - */ | ||
67 | - @Test | ||
68 | - public void checkExtendedErrorMsgConstructionWithName() { | ||
69 | - | ||
70 | - // Create an test error message | ||
71 | - String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, | ||
72 | - "Test Instance", ENTRY, | ||
73 | - "Extended Information"); | ||
74 | - | ||
75 | - // Check message. | ||
76 | - assertThat(testErrorMessage, | ||
77 | - is("Internal parser error detected: Invalid holder for contact \"Test Instance\"" | ||
78 | - + " before processing.\n" + "Error Information: Extended Information")); | ||
79 | - } | ||
80 | - | ||
81 | - /** | ||
82 | - * Checks for extended error message construction without parsable data type | ||
83 | - * name. | ||
84 | - */ | ||
85 | - @Test | ||
86 | - public void checkExtendedErrorMsgConstructionWithoutName() { | ||
87 | - | ||
88 | - // Create an test error message | ||
89 | - String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "", ENTRY, | ||
90 | - "Extended Information"); | ||
91 | - | ||
92 | - // Check message. | ||
93 | - assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact" | ||
94 | - + " before processing.\n" + "Error Information: Extended Information")); | ||
95 | - } | ||
96 | -} |
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.parser.parseutils; | ||
18 | - | ||
19 | -import org.junit.Rule; | ||
20 | -import org.junit.Test; | ||
21 | -import org.junit.rules.ExpectedException; | ||
22 | -import org.onosproject.yangutils.datamodel.YangRevision; | ||
23 | -import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
24 | -import org.onosproject.yangutils.parser.impl.TreeWalkListener; | ||
25 | - | ||
26 | -import static org.onosproject.yangutils.utils.YangConstructType.YANGBASE_DATA; | ||
27 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | ||
28 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | ||
29 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | ||
30 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty; | ||
31 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | ||
32 | - | ||
33 | -/** | ||
34 | - * Test case for testing listener validation util. | ||
35 | - */ | ||
36 | -public class ListenerValidationTest { | ||
37 | - | ||
38 | - @Rule | ||
39 | - public ExpectedException thrown = ExpectedException.none(); | ||
40 | - | ||
41 | - /** | ||
42 | - * Checks for exception in case parsable stack is empty while validating for | ||
43 | - * not empty scenario. | ||
44 | - */ | ||
45 | - @Test | ||
46 | - public void validateStackIsNotEmptyForEmptyStack() { | ||
47 | - | ||
48 | - String expectedError = constructListenerErrorMessage(MISSING_HOLDER, YANGBASE_DATA, "", EXIT); | ||
49 | - | ||
50 | - // Get the exception occurred during parsing. | ||
51 | - thrown.expect(ParserException.class); | ||
52 | - thrown.expectMessage(expectedError); | ||
53 | - | ||
54 | - // Create test walker and assign test error to it. | ||
55 | - TreeWalkListener testWalker = new TreeWalkListener(); | ||
56 | - | ||
57 | - checkStackIsNotEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT); | ||
58 | - } | ||
59 | - | ||
60 | - /** | ||
61 | - * Checks if there is no exception in case parsable stack is not empty while | ||
62 | - * validating for not empty scenario. | ||
63 | - */ | ||
64 | - @Test | ||
65 | - public void validateStackIsNotEmptyForNonEmptyStack() { | ||
66 | - | ||
67 | - // Create test walker and assign test error to it. | ||
68 | - TreeWalkListener testWalker = new TreeWalkListener(); | ||
69 | - | ||
70 | - // Create a temporary node of parsable. | ||
71 | - YangRevision tmpNode = new YangRevision(); | ||
72 | - testWalker.getParsedDataStack().push(tmpNode); | ||
73 | - | ||
74 | - checkStackIsNotEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT); | ||
75 | - } | ||
76 | - | ||
77 | - /** | ||
78 | - * Checks for exception in case parsable stack is not empty while validating | ||
79 | - * for empty scenario. | ||
80 | - */ | ||
81 | - @Test | ||
82 | - public void validateStackIsEmptyForNonEmptyStack() { | ||
83 | - | ||
84 | - String expectedError = constructListenerErrorMessage(MISSING_HOLDER, YANGBASE_DATA, "", EXIT); | ||
85 | - | ||
86 | - // Get the exception occurred during parsing. | ||
87 | - thrown.expect(ParserException.class); | ||
88 | - thrown.expectMessage(expectedError); | ||
89 | - | ||
90 | - // Create test walker and assign test error to it. | ||
91 | - TreeWalkListener testWalker = new TreeWalkListener(); | ||
92 | - | ||
93 | - // Create a temporary node of parsable. | ||
94 | - YangRevision tmpNode = new YangRevision(); | ||
95 | - testWalker.getParsedDataStack().push(tmpNode); | ||
96 | - | ||
97 | - checkStackIsEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT); | ||
98 | - } | ||
99 | - | ||
100 | - /** | ||
101 | - * Checks if there is no exception in case parsable stack is empty while | ||
102 | - * validating for empty scenario. | ||
103 | - */ | ||
104 | - @Test | ||
105 | - public void validateStackIsEmptyForEmptyStack() { | ||
106 | - | ||
107 | - // Create test walker and assign test error to it. | ||
108 | - TreeWalkListener testWalker = new TreeWalkListener(); | ||
109 | - | ||
110 | - checkStackIsEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT); | ||
111 | - } | ||
112 | -} |
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.parser.parseutils; | ||
18 | - | ||
19 | -import org.antlr.v4.runtime.ANTLRFileStream; | ||
20 | -import org.antlr.v4.runtime.ANTLRInputStream; | ||
21 | -import org.antlr.v4.runtime.CommonTokenStream; | ||
22 | -import org.antlr.v4.runtime.tree.ParseTree; | ||
23 | -import org.junit.Rule; | ||
24 | -import org.junit.Test; | ||
25 | -import org.junit.rules.ExpectedException; | ||
26 | -import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangLexer; | ||
27 | -import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ||
28 | -import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
29 | -import org.onosproject.yangutils.parser.impl.CustomExceptionMatcher; | ||
30 | -import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
31 | -import org.onosproject.yangutils.parser.impl.parserutils.ParseTreeErrorListener; | ||
32 | - | ||
33 | -import java.io.BufferedWriter; | ||
34 | -import java.io.File; | ||
35 | -import java.io.IOException; | ||
36 | - | ||
37 | -/** | ||
38 | - * Test case for testing parse tree error listener. | ||
39 | - */ | ||
40 | -public class ParseTreeErrorListenerTest { | ||
41 | - | ||
42 | - YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
43 | - File file; | ||
44 | - BufferedWriter out; | ||
45 | - | ||
46 | - @Rule | ||
47 | - public ExpectedException thrown = ExpectedException.none(); | ||
48 | - | ||
49 | - /** | ||
50 | - * Checks that no exception is generated for YANG file with valid syntax. | ||
51 | - */ | ||
52 | - @Test | ||
53 | - public void checkValidYangFileForNoSyntaxError() throws IOException { | ||
54 | - | ||
55 | - ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithoutSyntaxError.yang"); | ||
56 | - | ||
57 | - // Create a lexer that feeds off of input char stream. | ||
58 | - GeneratedYangLexer lexer = new GeneratedYangLexer(input); | ||
59 | - // Create a buffer of tokens pulled from the lexer. | ||
60 | - CommonTokenStream tokens = new CommonTokenStream(lexer); | ||
61 | - // Create a parser that feeds off the tokens buffer. | ||
62 | - GeneratedYangParser parser = new GeneratedYangParser(tokens); | ||
63 | - // Remove console error listener. | ||
64 | - parser.removeErrorListeners(); | ||
65 | - // Create instance of customized error listener. | ||
66 | - ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener(); | ||
67 | - // Add customized error listener to catch errors during parsing. | ||
68 | - parser.addErrorListener(parseTreeErrorListener); | ||
69 | - // Begin parsing YANG file and generate parse tree. | ||
70 | - ParseTree tree = parser.yangfile(); | ||
71 | - } | ||
72 | - | ||
73 | - /** | ||
74 | - * Checks that exception is generated for YANG file with invalid syntax. | ||
75 | - */ | ||
76 | - @Test | ||
77 | - public void checkInvalidYangFileForSyntaxError() throws IOException { | ||
78 | - | ||
79 | - // Get the exception occurred during parsing. | ||
80 | - thrown.expect(ParserException.class); | ||
81 | - thrown.expect(CustomExceptionMatcher.errorLocation(3, 0)); | ||
82 | - thrown.expectMessage("no viable alternative at input 'yang-version 1\\nnamespace'"); | ||
83 | - | ||
84 | - ANTLRInputStream input = new ANTLRFileStream("src/test/resources/YangFileWithSyntaxError.yang"); | ||
85 | - | ||
86 | - // Create a lexer that feeds off of input char stream. | ||
87 | - GeneratedYangLexer lexer = new GeneratedYangLexer(input); | ||
88 | - // Create a buffer of tokens pulled from the lexer. | ||
89 | - CommonTokenStream tokens = new CommonTokenStream(lexer); | ||
90 | - // Create a parser that feeds off the tokens buffer. | ||
91 | - GeneratedYangParser parser = new GeneratedYangParser(tokens); | ||
92 | - // Remove console error listener. | ||
93 | - parser.removeErrorListeners(); | ||
94 | - // Create instance of customized error listener. | ||
95 | - ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener(); | ||
96 | - // Add customized error listener to catch errors during parsing. | ||
97 | - parser.addErrorListener(parseTreeErrorListener); | ||
98 | - // Begin parsing YANG file and generate parse tree. | ||
99 | - ParseTree tree = parser.yangfile(); | ||
100 | - } | ||
101 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -125,16 +125,16 @@ public class AttributesJavaDataTypeTest { | ... | @@ -125,16 +125,16 @@ public class AttributesJavaDataTypeTest { |
125 | */ | 125 | */ |
126 | @Test | 126 | @Test |
127 | public void testgetJavaPkgInfo() { | 127 | public void testgetJavaPkgInfo() { |
128 | - test = getJavaImportPackage(getStubYangType(TYPE1), false, CLASS_INFO1, pluginConfig); | 128 | + test = getJavaImportPackage(getStubYangType(TYPE1), false, pluginConfig); |
129 | assertThat(true, is(test.equals(JAVA_LANG))); | 129 | assertThat(true, is(test.equals(JAVA_LANG))); |
130 | 130 | ||
131 | - test = getJavaImportPackage(getStubYangType(TYPE2), true, CLASS_INFO5, pluginConfig); | 131 | + test = getJavaImportPackage(getStubYangType(TYPE2), true, pluginConfig); |
132 | assertThat(true, is(test.equals(JAVA_LANG))); | 132 | assertThat(true, is(test.equals(JAVA_LANG))); |
133 | 133 | ||
134 | - test = getJavaImportPackage(getStubYangType(TYPE3), false, CLASS_INFO3, pluginConfig); | 134 | + test = getJavaImportPackage(getStubYangType(TYPE3), false, pluginConfig); |
135 | assertThat(null, is(test)); | 135 | assertThat(null, is(test)); |
136 | 136 | ||
137 | - test = getJavaImportPackage(getStubYangType(TYPE4), false, CLASS_INFO4, pluginConfig); | 137 | + test = getJavaImportPackage(getStubYangType(TYPE4), false, pluginConfig); |
138 | assertThat(null, is(test)); | 138 | assertThat(null, is(test)); |
139 | } | 139 | } |
140 | 140 | ||
... | @@ -145,7 +145,7 @@ public class AttributesJavaDataTypeTest { | ... | @@ -145,7 +145,7 @@ public class AttributesJavaDataTypeTest { |
145 | */ | 145 | */ |
146 | @Test | 146 | @Test |
147 | public void testForTypeDef() throws DataModelException { | 147 | public void testForTypeDef() throws DataModelException { |
148 | - test = getJavaImportPackage(getStubExtendedInfo(getStubYangType(TYPE_DEF)), false, TYPE_DEF_PKG, pluginConfig); | 148 | + test = getJavaImportPackage(getStubExtendedInfo(getStubYangType(TYPE_DEF)), false, pluginConfig); |
149 | assertThat(true, is(test.equals(TYPE_DEF_PKG))); | 149 | assertThat(true, is(test.equals(TYPE_DEF_PKG))); |
150 | } | 150 | } |
151 | 151 | ... | ... |
-
Please register or login to post a comment