Committed by
Thomas Vachuska
yang choice case translator + whitebox fix
Change-Id: I96f1855bc71a002335946150b51e911ae6ac2fb2
Showing
39 changed files
with
285 additions
and
148 deletions
| ... | @@ -286,7 +286,7 @@ public class YangCase extends YangNode | ... | @@ -286,7 +286,7 @@ public class YangCase extends YangNode |
| 286 | */ | 286 | */ |
| 287 | @Override | 287 | @Override |
| 288 | public YangConstructType getYangConstructType() { | 288 | public YangConstructType getYangConstructType() { |
| 289 | - return YangConstructType.CASE_DATA; | 289 | + return CASE_DATA; |
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | /** | 292 | /** |
| ... | @@ -311,7 +311,7 @@ public class YangCase extends YangNode | ... | @@ -311,7 +311,7 @@ public class YangCase extends YangNode |
| 311 | 311 | ||
| 312 | @Override | 312 | @Override |
| 313 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { | 313 | public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { |
| 314 | - if (getParent() == null || !(getParent() instanceof YangChoice)) { | 314 | + if (!(getParent() instanceof YangChoice)) { |
| 315 | throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " + | 315 | throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " + |
| 316 | getName()); | 316 | getName()); |
| 317 | } | 317 | } | ... | ... |
| ... | @@ -277,11 +277,11 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co | ... | @@ -277,11 +277,11 @@ public class YangChoice extends YangNode implements YangCommonInfo, Parsable, Co |
| 277 | /** | 277 | /** |
| 278 | * Returns the type of the data. | 278 | * Returns the type of the data. |
| 279 | * | 279 | * |
| 280 | - * @return returns CHOICE_DATA | 280 | + * @return choice data |
| 281 | */ | 281 | */ |
| 282 | @Override | 282 | @Override |
| 283 | public YangConstructType getYangConstructType() { | 283 | public YangConstructType getYangConstructType() { |
| 284 | - return YangConstructType.CHOICE_DATA; | 284 | + return CHOICE_DATA; |
| 285 | } | 285 | } |
| 286 | 286 | ||
| 287 | /** | 287 | /** | ... | ... |
| ... | @@ -72,7 +72,7 @@ public class YangEntityToResolveInfo<T> { | ... | @@ -72,7 +72,7 @@ public class YangEntityToResolveInfo<T> { |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | String prefix; | 74 | String prefix; |
| 75 | - T entityToResolve = (T) getEntityToResolve(); | 75 | + T entityToResolve = getEntityToResolve(); |
| 76 | if (entityToResolve instanceof YangType) { | 76 | if (entityToResolve instanceof YangType) { |
| 77 | prefix = ((YangType<?>) entityToResolve).getPrefix(); | 77 | prefix = ((YangType<?>) entityToResolve).getPrefix(); |
| 78 | } else if (entityToResolve instanceof YangUses) { | 78 | } else if (entityToResolve instanceof YangUses) { | ... | ... |
| ... | @@ -22,10 +22,10 @@ package org.onosproject.yangutils.datamodel; | ... | @@ -22,10 +22,10 @@ package org.onosproject.yangutils.datamodel; |
| 22 | public class YangNodeIdentifier { | 22 | public class YangNodeIdentifier { |
| 23 | 23 | ||
| 24 | // Name of the node. | 24 | // Name of the node. |
| 25 | - String name; | 25 | + private String name; |
| 26 | 26 | ||
| 27 | // Prefix of the node. | 27 | // Prefix of the node. |
| 28 | - String prefix; | 28 | + private String prefix; |
| 29 | 29 | ||
| 30 | /** | 30 | /** |
| 31 | * Creates an instance of YANG node identifier. | 31 | * Creates an instance of YANG node identifier. | ... | ... |
| ... | @@ -118,7 +118,7 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> | ... | @@ -118,7 +118,7 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> |
| 118 | if (getAscendingRangeIntervals() == null) { | 118 | if (getAscendingRangeIntervals() == null) { |
| 119 | throw new DataModelException("No range restriction info"); | 119 | throw new DataModelException("No range restriction info"); |
| 120 | } | 120 | } |
| 121 | - if (getAscendingRangeIntervals().size() == 0) { | 121 | + if (getAscendingRangeIntervals().isEmpty()) { |
| 122 | throw new DataModelException("No range interval info"); | 122 | throw new DataModelException("No range interval info"); |
| 123 | } | 123 | } |
| 124 | return getAscendingRangeIntervals().get(0).getStartValue(); | 124 | return getAscendingRangeIntervals().get(0).getStartValue(); |
| ... | @@ -134,7 +134,7 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> | ... | @@ -134,7 +134,7 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> |
| 134 | if (getAscendingRangeIntervals() == null) { | 134 | if (getAscendingRangeIntervals() == null) { |
| 135 | throw new DataModelException("No range restriction info"); | 135 | throw new DataModelException("No range restriction info"); |
| 136 | } | 136 | } |
| 137 | - if (getAscendingRangeIntervals().size() == 0) { | 137 | + if (getAscendingRangeIntervals().isEmpty()) { |
| 138 | throw new DataModelException("No range interval info"); | 138 | throw new DataModelException("No range interval info"); |
| 139 | } | 139 | } |
| 140 | return getAscendingRangeIntervals() | 140 | return getAscendingRangeIntervals() |
| ... | @@ -184,7 +184,7 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> | ... | @@ -184,7 +184,7 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> |
| 184 | public boolean isValidValueString(String valueInString) throws DataModelException { | 184 | public boolean isValidValueString(String valueInString) throws DataModelException { |
| 185 | 185 | ||
| 186 | if (getAscendingRangeIntervals() == null | 186 | if (getAscendingRangeIntervals() == null |
| 187 | - || getAscendingRangeIntervals().size() == 0) { | 187 | + || getAscendingRangeIntervals().isEmpty()) { |
| 188 | // Throw exception, At least one default range needs to be set in constructor or in linker. | 188 | // Throw exception, At least one default range needs to be set in constructor or in linker. |
| 189 | throw new DataModelException("Range interval missing in range restriction."); | 189 | throw new DataModelException("Range interval missing in range restriction."); |
| 190 | 190 | ... | ... |
| ... | @@ -21,6 +21,7 @@ import org.onosproject.yangutils.parser.Parsable; | ... | @@ -21,6 +21,7 @@ import org.onosproject.yangutils.parser.Parsable; |
| 21 | import org.onosproject.yangutils.utils.YangConstructType; | 21 | import org.onosproject.yangutils.utils.YangConstructType; |
| 22 | 22 | ||
| 23 | import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED; | 23 | import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED; |
| 24 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; | ||
| 24 | 25 | ||
| 25 | /* | 26 | /* |
| 26 | * Reference:RFC 6020. | 27 | * Reference:RFC 6020. |
| ... | @@ -294,20 +295,18 @@ public class YangType<T> | ... | @@ -294,20 +295,18 @@ public class YangType<T> |
| 294 | } | 295 | } |
| 295 | 296 | ||
| 296 | @Override | 297 | @Override |
| 297 | - public void resolve() { | 298 | + public void resolve() throws DataModelException { |
| 298 | /* | 299 | /* |
| 299 | Inherit the Restriction from the referred typedef definition. | 300 | Inherit the Restriction from the referred typedef definition. |
| 300 | */ | 301 | */ |
| 301 | - if (getDataType() != YangDataTypes.DERIVED) { | 302 | + if (getDataType() != DERIVED) { |
| 302 | - throw new RuntimeException("Resolve should only be called for derrived data types"); | 303 | + throw new DataModelException("Resolve should only be called for derived data types"); |
| 303 | } | 304 | } |
| 304 | 305 | ||
| 305 | YangDerivedInfo<?> derrivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo(); | 306 | YangDerivedInfo<?> derrivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo(); |
| 306 | YangType<?> baseType = derrivedInfo.getReferredTypeDef().getTypeDefBaseType(); | 307 | YangType<?> baseType = derrivedInfo.getReferredTypeDef().getTypeDefBaseType(); |
| 307 | - if (YangDataTypes.DERIVED == baseType.getDataType()) { | 308 | + if (DERIVED == baseType.getDataType() && baseType.getResolvableStatus() == INTRA_FILE_RESOLVED) { |
| 308 | - if (baseType.getResolvableStatus() == INTRA_FILE_RESOLVED) { | ||
| 309 | setResolvableStatus(INTRA_FILE_RESOLVED); | 309 | setResolvableStatus(INTRA_FILE_RESOLVED); |
| 310 | - } | ||
| 311 | } | 310 | } |
| 312 | //TODO: | 311 | //TODO: |
| 313 | } | 312 | } | ... | ... |
| ... | @@ -224,6 +224,5 @@ public final class AugmentListener { | ... | @@ -224,6 +224,5 @@ public final class AugmentListener { |
| 224 | */ | 224 | */ |
| 225 | private static void validateForChildNodes() { | 225 | private static void validateForChildNodes() { |
| 226 | //TODO: implement with linker. | 226 | //TODO: implement with linker. |
| 227 | - return; | ||
| 228 | } | 227 | } |
| 229 | } | 228 | } | ... | ... |
| ... | @@ -80,8 +80,8 @@ public final class BaseFileListener { | ... | @@ -80,8 +80,8 @@ public final class BaseFileListener { |
| 80 | checkStackIsNotEmpty(listener, MISSING_HOLDER, YANGBASE_DATA, "", EXIT); | 80 | checkStackIsNotEmpty(listener, MISSING_HOLDER, YANGBASE_DATA, "", EXIT); |
| 81 | 81 | ||
| 82 | // Data Model tree root node is set. | 82 | // Data Model tree root node is set. |
| 83 | - if ((listener.getParsedDataStack().peek() instanceof YangModule) | 83 | + if (listener.getParsedDataStack().peek() instanceof YangModule |
| 84 | - || (listener.getParsedDataStack().peek() instanceof YangSubModule)) { | 84 | + || listener.getParsedDataStack().peek() instanceof YangSubModule) { |
| 85 | listener.setRootNode((YangNode) listener.getParsedDataStack().pop()); | 85 | listener.setRootNode((YangNode) listener.getParsedDataStack().pop()); |
| 86 | } else { | 86 | } else { |
| 87 | throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, YANGBASE_DATA, "", EXIT)); | 87 | throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, YANGBASE_DATA, "", EXIT)); | ... | ... |
| ... | @@ -137,7 +137,7 @@ public final class BitListener { | ... | @@ -137,7 +137,7 @@ public final class BitListener { |
| 137 | switch (tmpNode.getYangConstructType()) { | 137 | switch (tmpNode.getYangConstructType()) { |
| 138 | case BITS_DATA: { | 138 | case BITS_DATA: { |
| 139 | YangBits yangBits = (YangBits) tmpNode; | 139 | YangBits yangBits = (YangBits) tmpNode; |
| 140 | - if ((ctx.bitBodyStatement() == null) || (ctx.bitBodyStatement().positionStatement() == null)) { | 140 | + if (ctx.bitBodyStatement() == null || ctx.bitBodyStatement().positionStatement() == null) { |
| 141 | int maxPosition = 0; | 141 | int maxPosition = 0; |
| 142 | boolean isPositionPresent = false; | 142 | boolean isPositionPresent = false; |
| 143 | 143 | ... | ... |
| ... | @@ -131,7 +131,7 @@ public final class EnumListener { | ... | @@ -131,7 +131,7 @@ public final class EnumListener { |
| 131 | switch (tmpNode.getYangConstructType()) { | 131 | switch (tmpNode.getYangConstructType()) { |
| 132 | case ENUMERATION_DATA: { | 132 | case ENUMERATION_DATA: { |
| 133 | YangEnumeration yangEnumeration = (YangEnumeration) tmpNode; | 133 | YangEnumeration yangEnumeration = (YangEnumeration) tmpNode; |
| 134 | - if ((ctx.enumStatementBody() == null) || (ctx.enumStatementBody().valueStatement() == null)) { | 134 | + if (ctx.enumStatementBody() == null || ctx.enumStatementBody().valueStatement() == null) { |
| 135 | int maxValue = 0; | 135 | int maxValue = 0; |
| 136 | boolean isValuePresent = false; | 136 | boolean isValuePresent = false; |
| 137 | 137 | ... | ... |
| ... | @@ -73,6 +73,8 @@ public final class LengthRestrictionListener { | ... | @@ -73,6 +73,8 @@ public final class LengthRestrictionListener { |
| 73 | 73 | ||
| 74 | private static final String PIPE = "|"; | 74 | private static final String PIPE = "|"; |
| 75 | private static final String LENGTH_INTERVAL = ".."; | 75 | private static final String LENGTH_INTERVAL = ".."; |
| 76 | + private static final int MAX_RANGE_BOUNDARY = 2; | ||
| 77 | + private static final int MIN_RANGE_BOUNDARY = 1; | ||
| 76 | 78 | ||
| 77 | /** | 79 | /** |
| 78 | * Creates a new length restriction listener. | 80 | * Creates a new length restriction listener. |
| ... | @@ -114,7 +116,8 @@ public final class LengthRestrictionListener { | ... | @@ -114,7 +116,8 @@ public final class LengthRestrictionListener { |
| 114 | GeneratedYangParser.LengthStatementContext ctx) { | 116 | GeneratedYangParser.LengthStatementContext ctx) { |
| 115 | 117 | ||
| 116 | YangStringRestriction stringRestriction; | 118 | YangStringRestriction stringRestriction; |
| 117 | - YangBuiltInDataTypeInfo<?> startValue, endValue; | 119 | + YangBuiltInDataTypeInfo<?> startValue; |
| 120 | + YangBuiltInDataTypeInfo<?> endValue; | ||
| 118 | YangRangeRestriction lengthRestriction = new YangRangeRestriction<>(); | 121 | YangRangeRestriction lengthRestriction = new YangRangeRestriction<>(); |
| 119 | 122 | ||
| 120 | if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) { | 123 | if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) { |
| ... | @@ -148,11 +151,12 @@ public final class LengthRestrictionListener { | ... | @@ -148,11 +151,12 @@ public final class LengthRestrictionListener { |
| 148 | String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE)); | 151 | String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE)); |
| 149 | 152 | ||
| 150 | for (String rangePart : rangeArguments) { | 153 | for (String rangePart : rangeArguments) { |
| 151 | - String startInterval, endInterval; | 154 | + String startInterval; |
| 155 | + String endInterval; | ||
| 152 | YangRangeInterval rangeInterval = new YangRangeInterval<>(); | 156 | YangRangeInterval rangeInterval = new YangRangeInterval<>(); |
| 153 | String[] rangeBoundary = rangePart.trim().split(Pattern.quote(LENGTH_INTERVAL)); | 157 | String[] rangeBoundary = rangePart.trim().split(Pattern.quote(LENGTH_INTERVAL)); |
| 154 | 158 | ||
| 155 | - if (rangeBoundary.length > 2) { | 159 | + if (rangeBoundary.length > MAX_RANGE_BOUNDARY) { |
| 156 | ParserException parserException = new ParserException("YANG file error : " + | 160 | ParserException parserException = new ParserException("YANG file error : " + |
| 157 | YangConstructType.getYangConstructType(LENGTH_DATA) + " " + rangeArgument + | 161 | YangConstructType.getYangConstructType(LENGTH_DATA) + " " + rangeArgument + |
| 158 | " is not valid."); | 162 | " is not valid."); |
| ... | @@ -161,7 +165,7 @@ public final class LengthRestrictionListener { | ... | @@ -161,7 +165,7 @@ public final class LengthRestrictionListener { |
| 161 | throw parserException; | 165 | throw parserException; |
| 162 | } | 166 | } |
| 163 | 167 | ||
| 164 | - if (rangeBoundary.length == 1) { | 168 | + if (rangeBoundary.length == MIN_RANGE_BOUNDARY) { |
| 165 | startInterval = rangeBoundary[0]; | 169 | startInterval = rangeBoundary[0]; |
| 166 | endInterval = rangeBoundary[0]; | 170 | endInterval = rangeBoundary[0]; |
| 167 | } else { | 171 | } else { | ... | ... |
| ... | @@ -70,6 +70,8 @@ public final class RangeRestrictionListener { | ... | @@ -70,6 +70,8 @@ public final class RangeRestrictionListener { |
| 70 | 70 | ||
| 71 | private static final String PIPE = "|"; | 71 | private static final String PIPE = "|"; |
| 72 | private static final String RANGE_INTERVAL = ".."; | 72 | private static final String RANGE_INTERVAL = ".."; |
| 73 | + private static final int MAX_RANGE_BOUNDARY = 2; | ||
| 74 | + private static final int MIN_RANGE_BOUNDARY = 1; | ||
| 73 | 75 | ||
| 74 | /** | 76 | /** |
| 75 | * Creates a new range restriction listener. | 77 | * Creates a new range restriction listener. |
| ... | @@ -110,18 +112,20 @@ public final class RangeRestrictionListener { | ... | @@ -110,18 +112,20 @@ public final class RangeRestrictionListener { |
| 110 | private static void setRangeRestriction(YangType type, | 112 | private static void setRangeRestriction(YangType type, |
| 111 | GeneratedYangParser.RangeStatementContext ctx) { | 113 | GeneratedYangParser.RangeStatementContext ctx) { |
| 112 | 114 | ||
| 113 | - YangBuiltInDataTypeInfo<?> startValue, endValue; | 115 | + YangBuiltInDataTypeInfo<?> startValue; |
| 116 | + YangBuiltInDataTypeInfo<?> endValue; | ||
| 114 | YangRangeRestriction rangeRestriction = new YangRangeRestriction(); | 117 | YangRangeRestriction rangeRestriction = new YangRangeRestriction(); |
| 115 | 118 | ||
| 116 | String rangeArgument = removeQuotesAndHandleConcat(ctx.range().getText()); | 119 | String rangeArgument = removeQuotesAndHandleConcat(ctx.range().getText()); |
| 117 | String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE)); | 120 | String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE)); |
| 118 | 121 | ||
| 119 | for (String rangePart : rangeArguments) { | 122 | for (String rangePart : rangeArguments) { |
| 120 | - String startInterval, endInterval; | 123 | + String startInterval; |
| 124 | + String endInterval; | ||
| 121 | YangRangeInterval rangeInterval = new YangRangeInterval(); | 125 | YangRangeInterval rangeInterval = new YangRangeInterval(); |
| 122 | String[] rangeBoundary = rangePart.trim().split(Pattern.quote(RANGE_INTERVAL)); | 126 | String[] rangeBoundary = rangePart.trim().split(Pattern.quote(RANGE_INTERVAL)); |
| 123 | 127 | ||
| 124 | - if (rangeBoundary.length > 2) { | 128 | + if (rangeBoundary.length > MAX_RANGE_BOUNDARY) { |
| 125 | ParserException parserException = new ParserException("YANG file error : " + | 129 | ParserException parserException = new ParserException("YANG file error : " + |
| 126 | YangConstructType.getYangConstructType(RANGE_DATA) + " " + rangeArgument + | 130 | YangConstructType.getYangConstructType(RANGE_DATA) + " " + rangeArgument + |
| 127 | " is not valid."); | 131 | " is not valid."); |
| ... | @@ -130,7 +134,7 @@ public final class RangeRestrictionListener { | ... | @@ -130,7 +134,7 @@ public final class RangeRestrictionListener { |
| 130 | throw parserException; | 134 | throw parserException; |
| 131 | } | 135 | } |
| 132 | 136 | ||
| 133 | - if (rangeBoundary.length == 1) { | 137 | + if (rangeBoundary.length == MIN_RANGE_BOUNDARY) { |
| 134 | startInterval = rangeBoundary[0]; | 138 | startInterval = rangeBoundary[0]; |
| 135 | endInterval = rangeBoundary[0]; | 139 | endInterval = rangeBoundary[0]; |
| 136 | } else { | 140 | } else { | ... | ... |
| ... | @@ -31,7 +31,6 @@ import org.onosproject.yangutils.parser.Parsable; | ... | @@ -31,7 +31,6 @@ import org.onosproject.yangutils.parser.Parsable; |
| 31 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 31 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
| 32 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 32 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 33 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 33 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
| 34 | -import org.onosproject.yangutils.utils.YangConstructType; | ||
| 35 | 34 | ||
| 36 | import static org.onosproject.yangutils.datamodel.ResolvableStatus.UNRESOLVED; | 35 | import static org.onosproject.yangutils.datamodel.ResolvableStatus.UNRESOLVED; |
| 37 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo; | 36 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo; |
| ... | @@ -89,7 +88,7 @@ public final class TypeListener { | ... | @@ -89,7 +88,7 @@ public final class TypeListener { |
| 89 | checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), ENTRY); | 88 | checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), ENTRY); |
| 90 | 89 | ||
| 91 | // Validate node identifier. | 90 | // Validate node identifier. |
| 92 | - YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), YangConstructType.TYPE_DATA, | 91 | + YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), TYPE_DATA, |
| 93 | ctx); | 92 | ctx); |
| 94 | 93 | ||
| 95 | // Obtain the YANG data type. | 94 | // Obtain the YANG data type. |
| ... | @@ -107,7 +106,7 @@ public final class TypeListener { | ... | @@ -107,7 +106,7 @@ public final class TypeListener { |
| 107 | switch (tmpData.getYangConstructType()) { | 106 | switch (tmpData.getYangConstructType()) { |
| 108 | case LEAF_DATA: | 107 | case LEAF_DATA: |
| 109 | YangLeaf leaf = (YangLeaf) tmpData; | 108 | YangLeaf leaf = (YangLeaf) tmpData; |
| 110 | - leaf.setDataType((YangType<?>) type); | 109 | + leaf.setDataType(type); |
| 111 | 110 | ||
| 112 | /* | 111 | /* |
| 113 | * If data type is derived, resolution information to be added | 112 | * If data type is derived, resolution information to be added |
| ... | @@ -139,7 +138,7 @@ public final class TypeListener { | ... | @@ -139,7 +138,7 @@ public final class TypeListener { |
| 139 | break; | 138 | break; |
| 140 | case LEAF_LIST_DATA: | 139 | case LEAF_LIST_DATA: |
| 141 | YangLeafList leafList = (YangLeafList) tmpData; | 140 | YangLeafList leafList = (YangLeafList) tmpData; |
| 142 | - leafList.setDataType((YangType<?>) type); | 141 | + leafList.setDataType(type); |
| 143 | 142 | ||
| 144 | /* | 143 | /* |
| 145 | * If data type is derived, resolution information to be added | 144 | * If data type is derived, resolution information to be added |
| ... | @@ -157,9 +156,6 @@ public final class TypeListener { | ... | @@ -157,9 +156,6 @@ public final class TypeListener { |
| 157 | ctx.string().getText(), EXIT)); | 156 | ctx.string().getText(), EXIT)); |
| 158 | } | 157 | } |
| 159 | 158 | ||
| 160 | - // Get the prefix information | ||
| 161 | - String prefix = ((YangType<?>) type).getPrefix(); | ||
| 162 | - | ||
| 163 | // Create empty derived info and attach it to type extended info. | 159 | // Create empty derived info and attach it to type extended info. |
| 164 | YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>(); | 160 | YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>(); |
| 165 | ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo); | 161 | ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo); |
| ... | @@ -174,7 +170,7 @@ public final class TypeListener { | ... | @@ -174,7 +170,7 @@ public final class TypeListener { |
| 174 | case UNION_DATA: | 170 | case UNION_DATA: |
| 175 | YangUnion unionNode = (YangUnion) tmpData; | 171 | YangUnion unionNode = (YangUnion) tmpData; |
| 176 | try { | 172 | try { |
| 177 | - unionNode.addType((YangType<?>) type); | 173 | + unionNode.addType(type); |
| 178 | } catch (DataModelException e) { | 174 | } catch (DataModelException e) { |
| 179 | ParserException parserException = new ParserException(e.getMessage()); | 175 | ParserException parserException = new ParserException(e.getMessage()); |
| 180 | parserException.setLine(ctx.getStart().getLine()); | 176 | parserException.setLine(ctx.getStart().getLine()); |
| ... | @@ -188,16 +184,13 @@ public final class TypeListener { | ... | @@ -188,16 +184,13 @@ public final class TypeListener { |
| 188 | */ | 184 | */ |
| 189 | if (yangDataTypes == YangDataTypes.DERIVED) { | 185 | if (yangDataTypes == YangDataTypes.DERIVED) { |
| 190 | 186 | ||
| 191 | - // Get the prefix information | ||
| 192 | - String prefix = ((YangType<?>) type).getPrefix(); | ||
| 193 | - | ||
| 194 | // Create empty derived info and attach it to type extended info. | 187 | // Create empty derived info and attach it to type extended info. |
| 195 | YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>(); | 188 | YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>(); |
| 196 | ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo); | 189 | ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo); |
| 197 | 190 | ||
| 198 | // Add resolution information to the list | 191 | // Add resolution information to the list |
| 199 | YangResolutionInfo resolutionInfo = | 192 | YangResolutionInfo resolutionInfo = |
| 200 | - new YangResolutionInfo<YangType>(type, (YangNode) unionNode, errorLine, errorPosition); | 193 | + new YangResolutionInfo<YangType>(type, unionNode, errorLine, errorPosition); |
| 201 | addToResolutionList(resolutionInfo, ctx); | 194 | addToResolutionList(resolutionInfo, ctx); |
| 202 | } | 195 | } |
| 203 | 196 | ||
| ... | @@ -205,24 +198,20 @@ public final class TypeListener { | ... | @@ -205,24 +198,20 @@ public final class TypeListener { |
| 205 | case TYPEDEF_DATA: | 198 | case TYPEDEF_DATA: |
| 206 | /* Prepare the base type info and set in derived type */ | 199 | /* Prepare the base type info and set in derived type */ |
| 207 | YangTypeDef typeDef = (YangTypeDef) tmpData; | 200 | YangTypeDef typeDef = (YangTypeDef) tmpData; |
| 208 | - typeDef.setDataType((YangType<?>) type); | 201 | + typeDef.setDataType(type); |
| 209 | 202 | ||
| 210 | /* | 203 | /* |
| 211 | * If data type is derived, resolution information to be added | 204 | * If data type is derived, resolution information to be added |
| 212 | * in resolution list. | 205 | * in resolution list. |
| 213 | */ | 206 | */ |
| 214 | if (yangDataTypes == YangDataTypes.DERIVED) { | 207 | if (yangDataTypes == YangDataTypes.DERIVED) { |
| 215 | - | ||
| 216 | - // Get the prefix information | ||
| 217 | - String prefix = ((YangType<?>) type).getPrefix(); | ||
| 218 | - | ||
| 219 | // Create empty derived info and attach it to type extended info. | 208 | // Create empty derived info and attach it to type extended info. |
| 220 | YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>(); | 209 | YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>(); |
| 221 | ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo); | 210 | ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo); |
| 222 | 211 | ||
| 223 | // Add resolution information to the list | 212 | // Add resolution information to the list |
| 224 | YangResolutionInfo resolutionInfo = | 213 | YangResolutionInfo resolutionInfo = |
| 225 | - new YangResolutionInfo<YangType>(type, (YangNode) typeDef, errorLine, errorPosition); | 214 | + new YangResolutionInfo<YangType>(type, typeDef, errorLine, errorPosition); |
| 226 | addToResolutionList(resolutionInfo, ctx); | 215 | addToResolutionList(resolutionInfo, ctx); |
| 227 | } | 216 | } |
| 228 | break; | 217 | break; | ... | ... |
| ... | @@ -51,7 +51,6 @@ import org.onosproject.yangutils.parser.Parsable; | ... | @@ -51,7 +51,6 @@ import org.onosproject.yangutils.parser.Parsable; |
| 51 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 51 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
| 52 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 52 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 53 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 53 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
| 54 | -import org.onosproject.yangutils.utils.YangConstructType; | ||
| 55 | 54 | ||
| 56 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | 55 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; |
| 57 | import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangUnionNode; | 56 | import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangUnionNode; |
| ... | @@ -214,7 +213,7 @@ public final class UnionListener { | ... | @@ -214,7 +213,7 @@ public final class UnionListener { |
| 214 | curNode.addChild(unionNode); | 213 | curNode.addChild(unionNode); |
| 215 | } catch (DataModelException e) { | 214 | } catch (DataModelException e) { |
| 216 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | 215 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, |
| 217 | - YangConstructType.UNION_DATA, "", ENTRY, e.getMessage())); | 216 | + UNION_DATA, "", ENTRY, e.getMessage())); |
| 218 | } | 217 | } |
| 219 | } | 218 | } |
| 220 | } | 219 | } | ... | ... |
| ... | @@ -117,8 +117,6 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -117,8 +117,6 @@ public class YangUtilManager extends AbstractMojo { |
| 117 | private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG); | 117 | private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG); |
| 118 | 118 | ||
| 119 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); | 119 | private YangUtilsParser yangUtilsParser = new YangUtilsParserManager(); |
| 120 | - private String searchDir; | ||
| 121 | - private String codeGenDir; | ||
| 122 | private YangNode rootNode; | 120 | private YangNode rootNode; |
| 123 | 121 | ||
| 124 | @Override | 122 | @Override |
| ... | @@ -132,12 +130,12 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -132,12 +130,12 @@ public class YangUtilManager extends AbstractMojo { |
| 132 | clean(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG); | 130 | clean(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG); |
| 133 | clean(getDirectory(baseDir, outputDirectory)); | 131 | clean(getDirectory(baseDir, outputDirectory)); |
| 134 | 132 | ||
| 135 | - searchDir = getDirectory(baseDir, yangFilesDir); | 133 | + String searchDir = getDirectory(baseDir, yangFilesDir); |
| 136 | - codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH; | 134 | + String codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH; |
| 137 | YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil(); | 135 | YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil(); |
| 138 | conflictResolver.setReplacementForPeriod(replacementForPeriod); | 136 | conflictResolver.setReplacementForPeriod(replacementForPeriod); |
| 139 | conflictResolver.setReplacementForHyphen(replacementForHyphen); | 137 | conflictResolver.setReplacementForHyphen(replacementForHyphen); |
| 140 | - conflictResolver.setReplacementForUnderscore(replacementForHyphen); | 138 | + conflictResolver.setReplacementForUnderscore(replacementForUnderscore); |
| 141 | List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); | 139 | List<String> yangFiles = YangFileScanner.getYangFiles(searchDir); |
| 142 | YangPluginConfig yangPlugin = new YangPluginConfig(); | 140 | YangPluginConfig yangPlugin = new YangPluginConfig(); |
| 143 | yangPlugin.setCodeGenDir(codeGenDir); | 141 | yangPlugin.setCodeGenDir(codeGenDir); | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
| ... | @@ -132,16 +132,14 @@ public final class JavaCodeGeneratorUtil { | ... | @@ -132,16 +132,14 @@ public final class JavaCodeGeneratorUtil { |
| 132 | 132 | ||
| 133 | /** | 133 | /** |
| 134 | * Free other YANG nodes of data-model tree when error occurs while file generation of current node. | 134 | * Free other YANG nodes of data-model tree when error occurs while file generation of current node. |
| 135 | - * | ||
| 136 | - * @throws DataModelException when fails to do datamodel operations | ||
| 137 | */ | 135 | */ |
| 138 | - public static void freeRestResources() throws DataModelException { | 136 | + public static void freeRestResources() { |
| 139 | 137 | ||
| 140 | YangNode curNode = getCurNode(); | 138 | YangNode curNode = getCurNode(); |
| 141 | YangNode tempNode = curNode; | 139 | YangNode tempNode = curNode; |
| 142 | TraversalType curTraversal = ROOT; | 140 | TraversalType curTraversal = ROOT; |
| 143 | 141 | ||
| 144 | - while (!(curNode == tempNode.getParent())) { | 142 | + while (curNode != tempNode.getParent()) { |
| 145 | 143 | ||
| 146 | if (curTraversal != PARENT && curNode.getChild() != null) { | 144 | if (curTraversal != PARENT && curNode.getChild() != null) { |
| 147 | curTraversal = CHILD; | 145 | curTraversal = CHILD; | ... | ... |
| ... | @@ -162,6 +162,29 @@ public class JavaImportData { | ... | @@ -162,6 +162,29 @@ public class JavaImportData { |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | /** | 164 | /** |
| 165 | + * Returns import for class. | ||
| 166 | + * | ||
| 167 | + * @return imports for class | ||
| 168 | + */ | ||
| 169 | + public List<String> getImports() { | ||
| 170 | + String importString; | ||
| 171 | + List<String> imports = new ArrayList<>(); | ||
| 172 | + | ||
| 173 | + for (JavaQualifiedTypeInfo importInfo : getImportSet()) { | ||
| 174 | + if (!importInfo.getPkgInfo().equals(EMPTY_STRING) && importInfo.getClassInfo() != null | ||
| 175 | + && !importInfo.getPkgInfo().equals(JAVA_LANG)) { | ||
| 176 | + importString = IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN | ||
| 177 | + + NEW_LINE; | ||
| 178 | + | ||
| 179 | + imports.add(importString); | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + sort(imports); | ||
| 184 | + return imports; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + /** | ||
| 165 | * Returns import for hash and equals method. | 188 | * Returns import for hash and equals method. |
| 166 | * | 189 | * |
| 167 | * @return import for hash and equals method | 190 | * @return import for hash and equals method | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
| ... | @@ -110,14 +110,14 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -110,14 +110,14 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
| 110 | * Current leaves holder is adding a leaf info as a attribute to the | 110 | * Current leaves holder is adding a leaf info as a attribute to the |
| 111 | * current class. | 111 | * current class. |
| 112 | */ | 112 | */ |
| 113 | - String className = AttributesJavaDataType.getJavaImportClass(attrType, isListAttr); | 113 | + String className = getJavaImportClass(attrType, isListAttr); |
| 114 | if (className != null) { | 114 | if (className != null) { |
| 115 | /* | 115 | /* |
| 116 | * Corresponding to the attribute type a class needs to be imported, | 116 | * Corresponding to the attribute type a class needs to be imported, |
| 117 | * since it can be a derived type or a usage of wrapper classes. | 117 | * since it can be a derived type or a usage of wrapper classes. |
| 118 | */ | 118 | */ |
| 119 | importInfo.setClassInfo(className); | 119 | importInfo.setClassInfo(className); |
| 120 | - String classPkg = AttributesJavaDataType.getJavaImportPackage(attrType, isListAttr, className); | 120 | + String classPkg = getJavaImportPackage(attrType, isListAttr, className); |
| 121 | if (classPkg == null) { | 121 | if (classPkg == null) { |
| 122 | throw new TranslatorException("import package cannot be null when the class is used"); | 122 | throw new TranslatorException("import package cannot be null when the class is used"); |
| 123 | } | 123 | } | ... | ... |
| ... | @@ -29,6 +29,7 @@ import org.onosproject.yangutils.datamodel.YangLeafList; | ... | @@ -29,6 +29,7 @@ import org.onosproject.yangutils.datamodel.YangLeafList; |
| 29 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; | 29 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
| 30 | import org.onosproject.yangutils.datamodel.YangNode; | 30 | import org.onosproject.yangutils.datamodel.YangNode; |
| 31 | import org.onosproject.yangutils.datamodel.YangType; | 31 | import org.onosproject.yangutils.datamodel.YangType; |
| 32 | +import org.onosproject.yangutils.datamodel.YangCase; | ||
| 32 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 33 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
| 33 | 34 | ||
| 34 | import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; | 35 | import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; |
| ... | @@ -110,6 +111,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ... | @@ -110,6 +111,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
| 110 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD; | 111 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD; |
| 111 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | 112 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 112 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 113 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
| 114 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | ||
| 115 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
| 113 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | 116 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
| 114 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; | 117 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; |
| 115 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | 118 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
| ... | @@ -393,6 +396,11 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -393,6 +396,11 @@ public class TempJavaCodeFragmentFiles { |
| 393 | private YangNode curYangNode; | 396 | private YangNode curYangNode; |
| 394 | 397 | ||
| 395 | /** | 398 | /** |
| 399 | + * Import info for case. | ||
| 400 | + */ | ||
| 401 | + private JavaQualifiedTypeInfo caseImportInfo; | ||
| 402 | + | ||
| 403 | + /** | ||
| 396 | * Current enum's value. | 404 | * Current enum's value. |
| 397 | */ | 405 | */ |
| 398 | private int enumValue; | 406 | private int enumValue; |
| ... | @@ -1130,9 +1138,8 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1130,9 +1138,8 @@ public class TempJavaCodeFragmentFiles { |
| 1130 | * Adds build method for interface. | 1138 | * Adds build method for interface. |
| 1131 | * | 1139 | * |
| 1132 | * @return build method for interface | 1140 | * @return build method for interface |
| 1133 | - * @throws IOException when fails to append to temporary file | ||
| 1134 | */ | 1141 | */ |
| 1135 | - public String addBuildMethodForInterface() throws IOException { | 1142 | + public String addBuildMethodForInterface() { |
| 1136 | return parseBuilderInterfaceBuildMethodString(generatedJavaClassName); | 1143 | return parseBuilderInterfaceBuildMethodString(generatedJavaClassName); |
| 1137 | } | 1144 | } |
| 1138 | 1145 | ||
| ... | @@ -1140,9 +1147,8 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1140,9 +1147,8 @@ public class TempJavaCodeFragmentFiles { |
| 1140 | * Adds build method's implementation for class. | 1147 | * Adds build method's implementation for class. |
| 1141 | * | 1148 | * |
| 1142 | * @return build method implementation for class | 1149 | * @return build method implementation for class |
| 1143 | - * @throws IOException when fails to append to temporary file | ||
| 1144 | */ | 1150 | */ |
| 1145 | - public String addBuildMethodImpl() throws IOException { | 1151 | + public String addBuildMethodImpl() { |
| 1146 | return getBuildString(generatedJavaClassName) + NEW_LINE; | 1152 | return getBuildString(generatedJavaClassName) + NEW_LINE; |
| 1147 | } | 1153 | } |
| 1148 | 1154 | ||
| ... | @@ -1162,9 +1168,8 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1162,9 +1168,8 @@ public class TempJavaCodeFragmentFiles { |
| 1162 | * @param modifier modifier for constructor. | 1168 | * @param modifier modifier for constructor. |
| 1163 | * @param toAppend string which need to be appended with the class name | 1169 | * @param toAppend string which need to be appended with the class name |
| 1164 | * @return default constructor for class | 1170 | * @return default constructor for class |
| 1165 | - * @throws IOException when fails to append to file | ||
| 1166 | */ | 1171 | */ |
| 1167 | - public String addDefaultConstructor(String modifier, String toAppend) throws IOException { | 1172 | + public String addDefaultConstructor(String modifier, String toAppend) { |
| 1168 | return NEW_LINE + getDefaultConstructorString(generatedJavaClassName + toAppend, modifier); | 1173 | return NEW_LINE + getDefaultConstructorString(generatedJavaClassName + toAppend, modifier); |
| 1169 | } | 1174 | } |
| 1170 | 1175 | ||
| ... | @@ -1172,9 +1177,8 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1172,9 +1177,8 @@ public class TempJavaCodeFragmentFiles { |
| 1172 | * Adds default constructor for class. | 1177 | * Adds default constructor for class. |
| 1173 | * | 1178 | * |
| 1174 | * @return default constructor for class | 1179 | * @return default constructor for class |
| 1175 | - * @throws IOException when fails to append to file | ||
| 1176 | */ | 1180 | */ |
| 1177 | - public String addOfMethod() throws IOException { | 1181 | + public String addOfMethod() { |
| 1178 | return getJavaDoc(OF_METHOD, generatedJavaClassName, false) | 1182 | return getJavaDoc(OF_METHOD, generatedJavaClassName, false) |
| 1179 | + getOfMethod(generatedJavaClassName, newAttrInfo); | 1183 | + getOfMethod(generatedJavaClassName, newAttrInfo); |
| 1180 | } | 1184 | } |
| ... | @@ -1380,6 +1384,28 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1380,6 +1384,28 @@ public class TempJavaCodeFragmentFiles { |
| 1380 | } | 1384 | } |
| 1381 | 1385 | ||
| 1382 | /** | 1386 | /** |
| 1387 | + * Adds parent's info to current node import list. | ||
| 1388 | + * | ||
| 1389 | + * @param curNode current node for which import list needs to be updated | ||
| 1390 | + */ | ||
| 1391 | + public void addParentInfoInCurNodeTempFile(YangNode curNode) { | ||
| 1392 | + caseImportInfo = new JavaQualifiedTypeInfo(); | ||
| 1393 | + YangNode parent = getParentNodeInGenCode(curNode); | ||
| 1394 | + if (!(parent instanceof JavaCodeGenerator)) { | ||
| 1395 | + throw new TranslatorException("missing parent node to contain current node info in generated file"); | ||
| 1396 | + } | ||
| 1397 | + | ||
| 1398 | + if (!(curNode instanceof HasJavaFileInfo)) { | ||
| 1399 | + throw new TranslatorException("missing java file information to get the package details " | ||
| 1400 | + + "of attribute corresponding to child node"); | ||
| 1401 | + } | ||
| 1402 | + | ||
| 1403 | + caseImportInfo.setClassInfo(getCaptialCase(getCamelCase(parent.getName(), null))); | ||
| 1404 | + caseImportInfo.setPkgInfo(((HasJavaFileInfo) parent).getJavaFileInfo().getPackage()); | ||
| 1405 | + ((HasJavaImportData) curNode).getJavaImportData().addImportInfo(curNode, caseImportInfo); | ||
| 1406 | + } | ||
| 1407 | + | ||
| 1408 | + /** | ||
| 1383 | * Adds leaf attributes in generated files. | 1409 | * Adds leaf attributes in generated files. |
| 1384 | * | 1410 | * |
| 1385 | * @param listOfLeaves list of YANG leaf | 1411 | * @param listOfLeaves list of YANG leaf |
| ... | @@ -1415,7 +1441,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1415,7 +1441,7 @@ public class TempJavaCodeFragmentFiles { |
| 1415 | * Check if the attribute is of type list, then the java.lang.list | 1441 | * Check if the attribute is of type list, then the java.lang.list |
| 1416 | * needs to be imported. | 1442 | * needs to be imported. |
| 1417 | */ | 1443 | */ |
| 1418 | - if (listOfLeafList.size() != 0) { | 1444 | + if (!listOfLeafList.isEmpty()) { |
| 1419 | if (!(curNode instanceof HasJavaImportData)) { | 1445 | if (!(curNode instanceof HasJavaImportData)) { |
| 1420 | throw new TranslatorException("missing import info in current data model node"); | 1446 | throw new TranslatorException("missing import info in current data model node"); |
| 1421 | 1447 | ||
| ... | @@ -1651,6 +1677,18 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1651,6 +1677,18 @@ public class TempJavaCodeFragmentFiles { |
| 1651 | if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0) { | 1677 | if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0) { |
| 1652 | 1678 | ||
| 1653 | /** | 1679 | /** |
| 1680 | + * Adds import for case. | ||
| 1681 | + */ | ||
| 1682 | + if (curNode instanceof YangCase) { | ||
| 1683 | + List<String> importData = ((HasJavaImportData) curNode).getJavaImportData().getImports(); | ||
| 1684 | + for (String importInfo : importData) { | ||
| 1685 | + if (!imports.contains(importInfo)) { | ||
| 1686 | + imports.add(importInfo); | ||
| 1687 | + } | ||
| 1688 | + } | ||
| 1689 | + } | ||
| 1690 | + | ||
| 1691 | + /** | ||
| 1654 | * Adds import for HasAugmentation class. | 1692 | * Adds import for HasAugmentation class. |
| 1655 | */ | 1693 | */ |
| 1656 | if (isHasAugmentationExtended(getExtendsList())) { | 1694 | if (isHasAugmentationExtended(getExtendsList())) { |
| ... | @@ -1689,6 +1727,10 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1689,6 +1727,10 @@ public class TempJavaCodeFragmentFiles { |
| 1689 | if (isAugmentedInfoExtended(getExtendsList())) { | 1727 | if (isAugmentedInfoExtended(getExtendsList())) { |
| 1690 | addAugmentedInfoImport(curNode, imports, false); | 1728 | addAugmentedInfoImport(curNode, imports, false); |
| 1691 | } | 1729 | } |
| 1730 | + | ||
| 1731 | + if (curNode instanceof YangCase) { | ||
| 1732 | + removeCaseImport(imports); | ||
| 1733 | + } | ||
| 1692 | } | 1734 | } |
| 1693 | 1735 | ||
| 1694 | if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0) { | 1736 | if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0) { |
| ... | @@ -1763,6 +1805,21 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1763,6 +1805,21 @@ public class TempJavaCodeFragmentFiles { |
| 1763 | } | 1805 | } |
| 1764 | 1806 | ||
| 1765 | /** | 1807 | /** |
| 1808 | + * Removes case import info from import list. | ||
| 1809 | + * | ||
| 1810 | + * @param imports list of imports | ||
| 1811 | + * @return import for class | ||
| 1812 | + */ | ||
| 1813 | + private List<String> removeCaseImport(List<String> imports) { | ||
| 1814 | + if (imports != null && caseImportInfo != null) { | ||
| 1815 | + String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() + | ||
| 1816 | + SEMI_COLAN + NEW_LINE; | ||
| 1817 | + imports.remove(caseImport); | ||
| 1818 | + } | ||
| 1819 | + return imports; | ||
| 1820 | + } | ||
| 1821 | + | ||
| 1822 | + /** | ||
| 1766 | * Removes all temporary file handles. | 1823 | * Removes all temporary file handles. |
| 1767 | * | 1824 | * |
| 1768 | * @param isErrorOccurred when translator fails to generate java files we need to close | 1825 | * @param isErrorOccurred when translator fails to generate java files we need to close | ... | ... |
| ... | @@ -139,8 +139,7 @@ public class YangJavaCase extends YangCase implements JavaCodeGeneratorInfo, Jav | ... | @@ -139,8 +139,7 @@ public class YangJavaCase extends YangCase implements JavaCodeGeneratorInfo, Jav |
| 139 | * Creates a java file using the YANG case info. | 139 | * Creates a java file using the YANG case info. |
| 140 | */ | 140 | */ |
| 141 | @Override | 141 | @Override |
| 142 | - public void generateCodeExit() { | 142 | + public void generateCodeExit() throws IOException { |
| 143 | - // TODO Auto-generated method stub | 143 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
| 144 | - | ||
| 145 | } | 144 | } |
| 146 | } | 145 | } | ... | ... |
| ... | @@ -24,7 +24,7 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; | ... | @@ -24,7 +24,7 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData; |
| 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 24 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
| 25 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 25 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
| 26 | 26 | ||
| 27 | -import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; | 27 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
| 28 | import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; | 28 | import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode; |
| 29 | 29 | ||
| 30 | /** | 30 | /** |
| ... | @@ -56,7 +56,7 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo, | ... | @@ -56,7 +56,7 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo, |
| 56 | super(); | 56 | super(); |
| 57 | setJavaFileInfo(new JavaFileInfo()); | 57 | setJavaFileInfo(new JavaFileInfo()); |
| 58 | setJavaImportData(new JavaImportData()); | 58 | setJavaImportData(new JavaImportData()); |
| 59 | - getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER); | 59 | + getJavaFileInfo().setGeneratedFileTypes(INTERFACE_MASK); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | /** | 62 | /** |
| ... | @@ -133,15 +133,13 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo, | ... | @@ -133,15 +133,13 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo, |
| 133 | @Override | 133 | @Override |
| 134 | public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException { | 134 | public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException { |
| 135 | generateCodeOfNode(this, yangPlugin, false); | 135 | generateCodeOfNode(this, yangPlugin, false); |
| 136 | - // TODO:getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this); | ||
| 137 | } | 136 | } |
| 138 | 137 | ||
| 139 | /** | 138 | /** |
| 140 | * Creates a java file using the YANG choice info. | 139 | * Creates a java file using the YANG choice info. |
| 141 | */ | 140 | */ |
| 142 | @Override | 141 | @Override |
| 143 | - public void generateCodeExit() { | 142 | + public void generateCodeExit() throws IOException { |
| 144 | - // TODO Auto-generated method stub | 143 | + getTempJavaCodeFragmentFiles().generateJavaFile(INTERFACE_MASK, this); |
| 145 | - | ||
| 146 | } | 144 | } |
| 147 | } | 145 | } | ... | ... |
| ... | @@ -109,7 +109,7 @@ public final class ClassDefinitionGenerator { | ... | @@ -109,7 +109,7 @@ public final class ClassDefinitionGenerator { |
| 109 | } | 109 | } |
| 110 | String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE; | 110 | String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE; |
| 111 | for (String extend : getExtendsList()) { | 111 | for (String extend : getExtendsList()) { |
| 112 | - def = def + extend + COMMA; | 112 | + def = def + extend + COMMA + SPACE; |
| 113 | } | 113 | } |
| 114 | def = trimAtLast(def, COMMA); | 114 | def = trimAtLast(def, COMMA); |
| 115 | 115 | ... | ... |
| ... | @@ -373,7 +373,7 @@ public final class MethodsGenerator { | ... | @@ -373,7 +373,7 @@ public final class MethodsGenerator { |
| 373 | private static String getReturnType(JavaAttributeInfo attr) { | 373 | private static String getReturnType(JavaAttributeInfo attr) { |
| 374 | 374 | ||
| 375 | String returnType = EMPTY_STRING; | 375 | String returnType = EMPTY_STRING; |
| 376 | - if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) { | 376 | + if (attr.isQualifiedName() && attr.getImportInfo().getPkgInfo() != null) { |
| 377 | returnType = attr.getImportInfo().getPkgInfo() + PERIOD; | 377 | returnType = attr.getImportInfo().getPkgInfo() + PERIOD; |
| 378 | } | 378 | } |
| 379 | returnType = returnType + attr.getImportInfo().getClassInfo(); | 379 | returnType = returnType + attr.getImportInfo().getClassInfo(); | ... | ... |
| ... | @@ -141,7 +141,7 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -141,7 +141,7 @@ public final class TempJavaCodeFragmentFilesUtils { |
| 141 | */ | 141 | */ |
| 142 | public static void prepareJavaFileGeneratorForExtendsList(List<String> extendsList) { | 142 | public static void prepareJavaFileGeneratorForExtendsList(List<String> extendsList) { |
| 143 | 143 | ||
| 144 | - if (!extendsList.isEmpty() && !extendsList.equals(null)) { | 144 | + if (extendsList != null && !extendsList.isEmpty()) { |
| 145 | JavaFileGenerator.setExtendsList(extendsList); | 145 | JavaFileGenerator.setExtendsList(extendsList); |
| 146 | JavaFileGenerator.setIsExtendsList(true); | 146 | JavaFileGenerator.setIsExtendsList(true); |
| 147 | } else { | 147 | } else { |
| ... | @@ -157,10 +157,7 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -157,10 +157,7 @@ public final class TempJavaCodeFragmentFilesUtils { |
| 157 | * @return true or false | 157 | * @return true or false |
| 158 | */ | 158 | */ |
| 159 | public static boolean isHasAugmentationExtended(List<String> extendsList) { | 159 | public static boolean isHasAugmentationExtended(List<String> extendsList) { |
| 160 | - if (extendsList != null && extendsList.contains(HAS_AUGMENTATION)) { | 160 | + return (extendsList != null && extendsList.contains(HAS_AUGMENTATION)); |
| 161 | - return true; | ||
| 162 | - } | ||
| 163 | - return false; | ||
| 164 | } | 161 | } |
| 165 | 162 | ||
| 166 | /** | 163 | /** |
| ... | @@ -170,10 +167,7 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -170,10 +167,7 @@ public final class TempJavaCodeFragmentFilesUtils { |
| 170 | * @return true or false | 167 | * @return true or false |
| 171 | */ | 168 | */ |
| 172 | public static boolean isAugmentedInfoExtended(List<String> extendsList) { | 169 | public static boolean isAugmentedInfoExtended(List<String> extendsList) { |
| 173 | - if (extendsList != null && extendsList.contains(AUGMENTED_INFO)) { | 170 | + return (extendsList != null && extendsList.contains(AUGMENTED_INFO)); |
| 174 | - return true; | ||
| 175 | - } | ||
| 176 | - return false; | ||
| 177 | } | 171 | } |
| 178 | 172 | ||
| 179 | /** | 173 | /** | ... | ... |
| ... | @@ -39,6 +39,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy | ... | @@ -39,6 +39,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy |
| 39 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 39 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
| 40 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
| 41 | import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; |
| 42 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
| 42 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | 43 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
| 43 | 44 | ||
| 44 | /** | 45 | /** |
| ... | @@ -159,8 +160,10 @@ public final class YangJavaModelUtils { | ... | @@ -159,8 +160,10 @@ public final class YangJavaModelUtils { |
| 159 | updatePackageInfo((HasJavaFileInfo) javaCodeGeneratorInfo, yangPlugin); | 160 | updatePackageInfo((HasJavaFileInfo) javaCodeGeneratorInfo, yangPlugin); |
| 160 | generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir()); | 161 | generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir()); |
| 161 | 162 | ||
| 162 | - javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | 163 | + if (!(javaCodeGeneratorInfo instanceof YangCase)) { |
| 163 | - .addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance); | 164 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
| 165 | + .addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance); | ||
| 166 | + } | ||
| 164 | 167 | ||
| 165 | /** | 168 | /** |
| 166 | * For augmentation of nodes. | 169 | * For augmentation of nodes. |
| ... | @@ -176,6 +179,21 @@ public final class YangJavaModelUtils { | ... | @@ -176,6 +179,21 @@ public final class YangJavaModelUtils { |
| 176 | } else if (javaCodeGeneratorInfo instanceof YangAugment) { | 179 | } else if (javaCodeGeneratorInfo instanceof YangAugment) { |
| 177 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(AUGMENTED_INFO); | 180 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(AUGMENTED_INFO); |
| 178 | } | 181 | } |
| 182 | + | ||
| 183 | + if (javaCodeGeneratorInfo instanceof YangCase) { | ||
| 184 | + YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent(); | ||
| 185 | + String curNodeName = ((YangCase) javaCodeGeneratorInfo).getName(); | ||
| 186 | + if (!parent.getName().equals(curNodeName)) { | ||
| 187 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(getCaptialCase(getCamelCase( | ||
| 188 | + parent.getName(), null))); | ||
| 189 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addParentInfoInCurNodeTempFile((YangNode) | ||
| 190 | + javaCodeGeneratorInfo); | ||
| 191 | + } else { | ||
| 192 | + String parentPackage = ((HasJavaFileInfo) parent).getJavaFileInfo().getPackage(); | ||
| 193 | + String caseExtendInfo = parentPackage + PERIOD + parent.getName(); | ||
| 194 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(caseExtendInfo); | ||
| 195 | + } | ||
| 196 | + } | ||
| 179 | } | 197 | } |
| 180 | 198 | ||
| 181 | /** | 199 | /** | ... | ... |
| ... | @@ -22,12 +22,6 @@ package org.onosproject.yangutils.translator.tojava.utils; | ... | @@ -22,12 +22,6 @@ package org.onosproject.yangutils.translator.tojava.utils; |
| 22 | public final class YangPluginConfig { | 22 | public final class YangPluginConfig { |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | - * Creates an object for YANG plugin config. | ||
| 26 | - */ | ||
| 27 | - public YangPluginConfig() { | ||
| 28 | - } | ||
| 29 | - | ||
| 30 | - /** | ||
| 31 | * Contains the code generation directory. | 25 | * Contains the code generation directory. |
| 32 | */ | 26 | */ |
| 33 | private String codeGenDir; | 27 | private String codeGenDir; |
| ... | @@ -38,6 +32,12 @@ public final class YangPluginConfig { | ... | @@ -38,6 +32,12 @@ public final class YangPluginConfig { |
| 38 | private YangToJavaNamingConflictUtil conflictResolver; | 32 | private YangToJavaNamingConflictUtil conflictResolver; |
| 39 | 33 | ||
| 40 | /** | 34 | /** |
| 35 | + * Creates an object for YANG plugin config. | ||
| 36 | + */ | ||
| 37 | + public YangPluginConfig() { | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | * Sets the path of the java code where it has to be generated. | 41 | * Sets the path of the java code where it has to be generated. |
| 42 | * | 42 | * |
| 43 | * @param codeGenDir path of the directory | 43 | * @param codeGenDir path of the directory | ... | ... |
| ... | @@ -26,12 +26,6 @@ import java.util.List; | ... | @@ -26,12 +26,6 @@ import java.util.List; |
| 26 | public final class UtilConstants { | 26 | public final class UtilConstants { |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | - * Creates an instance of util constants. | ||
| 30 | - */ | ||
| 31 | - private UtilConstants() { | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - /** | ||
| 35 | * JavaDocs for impl class. | 29 | * JavaDocs for impl class. |
| 36 | */ | 30 | */ |
| 37 | public static final String IMPL_CLASS_JAVA_DOC = " * Represents the implementation of "; | 31 | public static final String IMPL_CLASS_JAVA_DOC = " * Represents the implementation of "; |
| ... | @@ -841,4 +835,10 @@ public final class UtilConstants { | ... | @@ -841,4 +835,10 @@ public final class UtilConstants { |
| 841 | * Static attribute for array list. | 835 | * Static attribute for array list. |
| 842 | */ | 836 | */ |
| 843 | public static final String ARRAY_LIST = "ArrayList"; | 837 | public static final String ARRAY_LIST = "ArrayList"; |
| 838 | + | ||
| 839 | + /** | ||
| 840 | + * Creates an instance of util constants. | ||
| 841 | + */ | ||
| 842 | + private UtilConstants() { | ||
| 843 | + } | ||
| 844 | } | 844 | } | ... | ... |
| ... | @@ -55,10 +55,7 @@ public final class FileSystemUtil { | ... | @@ -55,10 +55,7 @@ public final class FileSystemUtil { |
| 55 | public static boolean doesPackageExist(String pkg) { | 55 | public static boolean doesPackageExist(String pkg) { |
| 56 | File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg)); | 56 | File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg)); |
| 57 | File pkgWithFile = new File(pkgDir + SLASH + "package-info.java"); | 57 | File pkgWithFile = new File(pkgDir + SLASH + "package-info.java"); |
| 58 | - if (pkgDir.exists() && pkgWithFile.isFile()) { | 58 | + return (pkgDir.exists() && pkgWithFile.isFile()); |
| 59 | - return true; | ||
| 60 | - } | ||
| 61 | - return false; | ||
| 62 | } | 59 | } |
| 63 | 60 | ||
| 64 | /** | 61 | /** | ... | ... |
| ... | @@ -376,10 +376,10 @@ public final class JavaDocGen { | ... | @@ -376,10 +376,10 @@ public final class JavaDocGen { |
| 376 | * @return javaDocs | 376 | * @return javaDocs |
| 377 | */ | 377 | */ |
| 378 | private static String generateForTypeDefSetter(String attribute) { | 378 | private static String generateForTypeDefSetter(String attribute) { |
| 379 | - return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION | 379 | + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION |
| 380 | + JAVA_DOC_SETTERS_COMMON + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK | 380 | + JAVA_DOC_SETTERS_COMMON + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK |
| 381 | + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute | 381 | + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute |
| 382 | - + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE); | 382 | + + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
| 383 | } | 383 | } |
| 384 | 384 | ||
| 385 | /** | 385 | /** |
| ... | @@ -491,10 +491,9 @@ public final class JavaDocGen { | ... | @@ -491,10 +491,9 @@ public final class JavaDocGen { |
| 491 | * @return javaDocs for type constructor | 491 | * @return javaDocs for type constructor |
| 492 | */ | 492 | */ |
| 493 | private static String generateForTypeConstructor(String attribute) { | 493 | private static String generateForTypeConstructor(String attribute) { |
| 494 | - | 494 | + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR |
| 495 | - return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR | ||
| 496 | + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION | 495 | + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION |
| 497 | + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE | 496 | + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE |
| 498 | - + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE); | 497 | + + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; |
| 499 | } | 498 | } |
| 500 | } | 499 | } | ... | ... |
| ... | @@ -223,7 +223,7 @@ public final class YangIoUtils { | ... | @@ -223,7 +223,7 @@ public final class YangIoUtils { |
| 223 | 223 | ||
| 224 | for (File file : files) { | 224 | for (File file : files) { |
| 225 | Files.copy(file.toPath(), | 225 | Files.copy(file.toPath(), |
| 226 | - (new File(path + file.getName())).toPath(), | 226 | + new File(path + file.getName()).toPath(), |
| 227 | StandardCopyOption.REPLACE_EXISTING); | 227 | StandardCopyOption.REPLACE_EXISTING); |
| 228 | } | 228 | } |
| 229 | Resource rsc = new Resource(); | 229 | Resource rsc = new Resource(); | ... | ... |
| ... | @@ -53,7 +53,7 @@ public class IntraFileTypeLinkingTest { | ... | @@ -53,7 +53,7 @@ public class IntraFileTypeLinkingTest { |
| 53 | YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang"); | 53 | YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang"); |
| 54 | 54 | ||
| 55 | // Check whether the data model tree returned is of type module. | 55 | // Check whether the data model tree returned is of type module. |
| 56 | - assertThat((node instanceof YangModule), is(true)); | 56 | + assertThat(node instanceof YangModule, is(true)); |
| 57 | 57 | ||
| 58 | // Check whether the node type is set properly to module. | 58 | // Check whether the node type is set properly to module. |
| 59 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | 59 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| ... | @@ -72,7 +72,7 @@ public class IntraFileTypeLinkingTest { | ... | @@ -72,7 +72,7 @@ public class IntraFileTypeLinkingTest { |
| 72 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 72 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 73 | is((YangTypeDef) node.getChild())); | 73 | is((YangTypeDef) node.getChild())); |
| 74 | 74 | ||
| 75 | - assertThat((leafInfo.getDataType().getResolvableStatus()), | 75 | + assertThat(leafInfo.getDataType().getResolvableStatus(), |
| 76 | is(ResolvableStatus.RESOLVED)); | 76 | is(ResolvableStatus.RESOLVED)); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| ... | @@ -111,7 +111,7 @@ public class IntraFileTypeLinkingTest { | ... | @@ -111,7 +111,7 @@ public class IntraFileTypeLinkingTest { |
| 111 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 111 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 112 | is((YangTypeDef) node.getChild())); | 112 | is((YangTypeDef) node.getChild())); |
| 113 | 113 | ||
| 114 | - assertThat((leafInfo.getDataType().getResolvableStatus()), | 114 | + assertThat(leafInfo.getDataType().getResolvableStatus(), |
| 115 | is(ResolvableStatus.RESOLVED)); | 115 | is(ResolvableStatus.RESOLVED)); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| ... | @@ -151,7 +151,7 @@ public class IntraFileTypeLinkingTest { | ... | @@ -151,7 +151,7 @@ public class IntraFileTypeLinkingTest { |
| 151 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 151 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 152 | is((YangTypeDef) node.getChild().getNextSibling())); | 152 | is((YangTypeDef) node.getChild().getNextSibling())); |
| 153 | 153 | ||
| 154 | - assertThat((leafInfo.getDataType().getResolvableStatus()), | 154 | + assertThat(leafInfo.getDataType().getResolvableStatus(), |
| 155 | is(ResolvableStatus.RESOLVED)); | 155 | is(ResolvableStatus.RESOLVED)); |
| 156 | } | 156 | } |
| 157 | 157 | ||
| ... | @@ -191,7 +191,7 @@ public class IntraFileTypeLinkingTest { | ... | @@ -191,7 +191,7 @@ public class IntraFileTypeLinkingTest { |
| 191 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 191 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 192 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); | 192 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); |
| 193 | 193 | ||
| 194 | - assertThat((leafInfo.getDataType().getResolvableStatus()), | 194 | + assertThat(leafInfo.getDataType().getResolvableStatus(), |
| 195 | is(ResolvableStatus.RESOLVED)); | 195 | is(ResolvableStatus.RESOLVED)); |
| 196 | } | 196 | } |
| 197 | 197 | ||
| ... | @@ -228,21 +228,21 @@ public class IntraFileTypeLinkingTest { | ... | @@ -228,21 +228,21 @@ public class IntraFileTypeLinkingTest { |
| 228 | 228 | ||
| 229 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 229 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 230 | is((YangTypeDef) yangList.getChild())); | 230 | is((YangTypeDef) yangList.getChild())); |
| 231 | - assertThat((leafInfo.getDataType().getResolvableStatus()), | 231 | + assertThat(leafInfo.getDataType().getResolvableStatus(), |
| 232 | is(ResolvableStatus.RESOLVED)); | 232 | is(ResolvableStatus.RESOLVED)); |
| 233 | 233 | ||
| 234 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); | 234 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); |
| 235 | 235 | ||
| 236 | assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 236 | assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 237 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); | 237 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); |
| 238 | - assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()), | 238 | + assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(), |
| 239 | is(ResolvableStatus.RESOLVED)); | 239 | is(ResolvableStatus.RESOLVED)); |
| 240 | 240 | ||
| 241 | YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling(); | 241 | YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling(); |
| 242 | 242 | ||
| 243 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 243 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 244 | is((YangTypeDef) node.getChild())); | 244 | is((YangTypeDef) node.getChild())); |
| 245 | - assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()), | 245 | + assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(), |
| 246 | is(ResolvableStatus.RESOLVED)); | 246 | is(ResolvableStatus.RESOLVED)); |
| 247 | } | 247 | } |
| 248 | 248 | ||
| ... | @@ -280,21 +280,21 @@ public class IntraFileTypeLinkingTest { | ... | @@ -280,21 +280,21 @@ public class IntraFileTypeLinkingTest { |
| 280 | 280 | ||
| 281 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 281 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 282 | is((YangTypeDef) yangList.getChild())); | 282 | is((YangTypeDef) yangList.getChild())); |
| 283 | - assertThat((leafInfo.getDataType().getResolvableStatus()), | 283 | + assertThat(leafInfo.getDataType().getResolvableStatus(), |
| 284 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); | 284 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); |
| 285 | 285 | ||
| 286 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); | 286 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); |
| 287 | 287 | ||
| 288 | assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 288 | assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 289 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); | 289 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); |
| 290 | - assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()), | 290 | + assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(), |
| 291 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); | 291 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); |
| 292 | 292 | ||
| 293 | YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling(); | 293 | YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling(); |
| 294 | 294 | ||
| 295 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 295 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 296 | is((YangTypeDef) node.getChild())); | 296 | is((YangTypeDef) node.getChild())); |
| 297 | - assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()), | 297 | + assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(), |
| 298 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); | 298 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); |
| 299 | } | 299 | } |
| 300 | 300 | ||
| ... | @@ -331,21 +331,21 @@ public class IntraFileTypeLinkingTest { | ... | @@ -331,21 +331,21 @@ public class IntraFileTypeLinkingTest { |
| 331 | 331 | ||
| 332 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 332 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 333 | is((YangTypeDef) yangList.getChild())); | 333 | is((YangTypeDef) yangList.getChild())); |
| 334 | - assertThat((leafInfo.getDataType().getResolvableStatus()), | 334 | + assertThat(leafInfo.getDataType().getResolvableStatus(), |
| 335 | is(ResolvableStatus.RESOLVED)); | 335 | is(ResolvableStatus.RESOLVED)); |
| 336 | 336 | ||
| 337 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); | 337 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); |
| 338 | 338 | ||
| 339 | assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 339 | assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 340 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); | 340 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); |
| 341 | - assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()), | 341 | + assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(), |
| 342 | is(ResolvableStatus.RESOLVED)); | 342 | is(ResolvableStatus.RESOLVED)); |
| 343 | 343 | ||
| 344 | YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling(); | 344 | YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling(); |
| 345 | 345 | ||
| 346 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 346 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 347 | is((YangTypeDef) node.getChild())); | 347 | is((YangTypeDef) node.getChild())); |
| 348 | - assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()), | 348 | + assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(), |
| 349 | is(ResolvableStatus.RESOLVED)); | 349 | is(ResolvableStatus.RESOLVED)); |
| 350 | } | 350 | } |
| 351 | 351 | ||
| ... | @@ -383,7 +383,7 @@ public class IntraFileTypeLinkingTest { | ... | @@ -383,7 +383,7 @@ public class IntraFileTypeLinkingTest { |
| 383 | 383 | ||
| 384 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 384 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 385 | is((YangTypeDef) yangList.getChild())); | 385 | is((YangTypeDef) yangList.getChild())); |
| 386 | - assertThat((leafInfo.getDataType().getResolvableStatus()), | 386 | + assertThat(leafInfo.getDataType().getResolvableStatus(), |
| 387 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); | 387 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); |
| 388 | 388 | ||
| 389 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); | 389 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); |
| ... | @@ -392,7 +392,7 @@ public class IntraFileTypeLinkingTest { | ... | @@ -392,7 +392,7 @@ public class IntraFileTypeLinkingTest { |
| 392 | 392 | ||
| 393 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), | 393 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 394 | is((YangTypeDef) node.getChild())); | 394 | is((YangTypeDef) node.getChild())); |
| 395 | - assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()), | 395 | + assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(), |
| 396 | is(ResolvableStatus.RESOLVED)); | 396 | is(ResolvableStatus.RESOLVED)); |
| 397 | } | 397 | } |
| 398 | 398 | ... | ... |
| ... | @@ -27,22 +27,22 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; | ... | @@ -27,22 +27,22 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 27 | */ | 27 | */ |
| 28 | public final class CustomExceptionMatcher extends TypeSafeMatcher<ParserException> { | 28 | public final class CustomExceptionMatcher extends TypeSafeMatcher<ParserException> { |
| 29 | 29 | ||
| 30 | + private int actualLine; | ||
| 31 | + private final int expectedLine; | ||
| 32 | + private int actualCharPosition; | ||
| 33 | + private final int expectedCharPosition; | ||
| 34 | + | ||
| 30 | /** | 35 | /** |
| 31 | * Customized exception matcher to match error location. | 36 | * Customized exception matcher to match error location. |
| 32 | * | 37 | * |
| 33 | * @param line error line | 38 | * @param line error line |
| 34 | * @param charPosition error character position | 39 | * @param charPosition error character position |
| 35 | - * @return | 40 | + * @return customized exception matcher to match error location |
| 36 | */ | 41 | */ |
| 37 | public static CustomExceptionMatcher errorLocation(int line, int charPosition) { | 42 | public static CustomExceptionMatcher errorLocation(int line, int charPosition) { |
| 38 | return new CustomExceptionMatcher(line, charPosition); | 43 | return new CustomExceptionMatcher(line, charPosition); |
| 39 | } | 44 | } |
| 40 | 45 | ||
| 41 | - private int actualLine; | ||
| 42 | - private final int expectedLine; | ||
| 43 | - private int actualCharPosition; | ||
| 44 | - private final int expectedCharPosition; | ||
| 45 | - | ||
| 46 | private CustomExceptionMatcher(int expectedLine, int expectedCharPosition) { | 46 | private CustomExceptionMatcher(int expectedLine, int expectedCharPosition) { |
| 47 | this.expectedLine = expectedLine; | 47 | this.expectedLine = expectedLine; |
| 48 | this.expectedCharPosition = expectedCharPosition; | 48 | this.expectedCharPosition = expectedCharPosition; | ... | ... |
| ... | @@ -54,9 +54,6 @@ public class AugmentListenerTest { | ... | @@ -54,9 +54,6 @@ public class AugmentListenerTest { |
| 54 | assertThat(yangNode.getName(), is("Test")); | 54 | assertThat(yangNode.getName(), is("Test")); |
| 55 | 55 | ||
| 56 | YangAugment yangAugment = (YangAugment) yangNode.getChild(); | 56 | YangAugment yangAugment = (YangAugment) yangNode.getChild(); |
| 57 | - if (yangAugment.getTargetNode().isEmpty()) { | ||
| 58 | - System.out.println("list is empty"); | ||
| 59 | - } | ||
| 60 | ListIterator<YangNodeIdentifier> nodeIdentifierIterator = yangAugment.getTargetNode().listIterator(); | 57 | ListIterator<YangNodeIdentifier> nodeIdentifierIterator = yangAugment.getTargetNode().listIterator(); |
| 61 | YangNodeIdentifier yangNodeIdentifier = nodeIdentifierIterator.next(); | 58 | YangNodeIdentifier yangNodeIdentifier = nodeIdentifierIterator.next(); |
| 62 | assertThat(yangNodeIdentifier.getPrefix(), is("if")); | 59 | assertThat(yangNodeIdentifier.getPrefix(), is("if")); | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.yangutils.translator.tojava.utils; | ||
| 18 | + | ||
| 19 | +import java.io.IOException; | ||
| 20 | +import org.junit.Test; | ||
| 21 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
| 22 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
| 23 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
| 24 | + | ||
| 25 | +import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode; | ||
| 26 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * Unit tests for choice-case translator. | ||
| 30 | + */ | ||
| 31 | +public final class ChoiceCaseTranslatorTest { | ||
| 32 | + | ||
| 33 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * Checks choice-case translation should not result in any exception. | ||
| 37 | + */ | ||
| 38 | + @Test | ||
| 39 | + public void processChoiceCaseTranslator() throws IOException, ParserException { | ||
| 40 | + | ||
| 41 | + String userDir = System.getProperty("user.dir"); | ||
| 42 | + YangNode node = manager.getDataModel("src/test/resources/ChoiceCaseTranslator.yang"); | ||
| 43 | + | ||
| 44 | + YangPluginConfig yangPluginConfig = new YangPluginConfig(); | ||
| 45 | + yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/"); | ||
| 46 | + | ||
| 47 | + generateJavaCode(node, yangPluginConfig); | ||
| 48 | + | ||
| 49 | + clean(userDir + "/target/ChoiceCaseTestGenFile/"); | ||
| 50 | + } | ||
| 51 | + // TODO enhance the test cases, after having a framework of translator test. | ||
| 52 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -28,21 +28,18 @@ import java.util.Calendar; | ... | @@ -28,21 +28,18 @@ import java.util.Calendar; |
| 28 | import org.junit.Rule; | 28 | import org.junit.Rule; |
| 29 | import org.junit.Test; | 29 | import org.junit.Test; |
| 30 | import org.junit.rules.ExpectedException; | 30 | import org.junit.rules.ExpectedException; |
| 31 | -import org.slf4j.Logger; | ||
| 32 | 31 | ||
| 33 | import static org.apache.commons.io.FileUtils.contentEquals; | 32 | import static org.apache.commons.io.FileUtils.contentEquals; |
| 34 | import static org.hamcrest.core.Is.is; | 33 | import static org.hamcrest.core.Is.is; |
| 35 | import static org.hamcrest.core.IsNot.not; | 34 | import static org.hamcrest.core.IsNot.not; |
| 36 | import static org.junit.Assert.assertThat; | 35 | import static org.junit.Assert.assertThat; |
| 37 | import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader; | 36 | import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader; |
| 38 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 39 | 37 | ||
| 40 | /** | 38 | /** |
| 41 | * Unit Tests for the CopyrightHeader contents. | 39 | * Unit Tests for the CopyrightHeader contents. |
| 42 | */ | 40 | */ |
| 43 | public final class CopyrightHeaderTest { | 41 | public final class CopyrightHeaderTest { |
| 44 | 42 | ||
| 45 | - private final Logger log = getLogger(getClass()); | ||
| 46 | private static final String COPYRIGHTS_FIRST_LINE = "/*\n * Copyright " + Calendar.getInstance().get(Calendar.YEAR) | 43 | private static final String COPYRIGHTS_FIRST_LINE = "/*\n * Copyright " + Calendar.getInstance().get(Calendar.YEAR) |
| 47 | + "-present Open Networking Laboratory\n"; | 44 | + "-present Open Networking Laboratory\n"; |
| 48 | @Rule | 45 | @Rule | ... | ... |
| ... | @@ -26,14 +26,12 @@ import java.util.List; | ... | @@ -26,14 +26,12 @@ import java.util.List; |
| 26 | import org.junit.Rule; | 26 | import org.junit.Rule; |
| 27 | import org.junit.Test; | 27 | import org.junit.Test; |
| 28 | import org.junit.rules.ExpectedException; | 28 | import org.junit.rules.ExpectedException; |
| 29 | -import org.slf4j.Logger; | ||
| 30 | 29 | ||
| 31 | import static org.hamcrest.core.Is.is; | 30 | import static org.hamcrest.core.Is.is; |
| 32 | import static org.hamcrest.core.IsNot.not; | 31 | import static org.hamcrest.core.IsNot.not; |
| 33 | import static org.junit.Assert.assertThat; | 32 | import static org.junit.Assert.assertThat; |
| 34 | import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getJavaFiles; | 33 | import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getJavaFiles; |
| 35 | import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getYangFiles; | 34 | import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getYangFiles; |
| 36 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 37 | 35 | ||
| 38 | import static java.io.File.separator; | 36 | import static java.io.File.separator; |
| 39 | 37 | ||
| ... | @@ -42,8 +40,6 @@ import static java.io.File.separator; | ... | @@ -42,8 +40,6 @@ import static java.io.File.separator; |
| 42 | */ | 40 | */ |
| 43 | public final class YangFileScannerTest { | 41 | public final class YangFileScannerTest { |
| 44 | 42 | ||
| 45 | - private final Logger log = getLogger(getClass()); | ||
| 46 | - | ||
| 47 | @Rule | 43 | @Rule |
| 48 | public ExpectedException thrown = ExpectedException.none(); | 44 | public ExpectedException thrown = ExpectedException.none(); |
| 49 | 45 | ... | ... |
| 1 | +module Test { | ||
| 2 | + yang-version 1; | ||
| 3 | + namespace http://huawei.com; | ||
| 4 | + prefix Ant; | ||
| 5 | + container food { | ||
| 6 | + choice snack { | ||
| 7 | + case sports-arena { | ||
| 8 | + leaf pretzel { | ||
| 9 | + type string; | ||
| 10 | + } | ||
| 11 | + leaf beer { | ||
| 12 | + type string; | ||
| 13 | + } | ||
| 14 | + } | ||
| 15 | + case late-night { | ||
| 16 | + leaf chocolate { | ||
| 17 | + type string; | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | +} |
-
Please register or login to post a comment