Gaurav Agrawal
Committed by Gerrit Code Review

YANG: Restriction resolution implementation

Change-Id: I69503e8229def07b289a0c8c762bfe0ae5530232
Showing 33 changed files with 273 additions and 392 deletions
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.datamodel;
18 +
19 +/**
20 + * Abstraction of location information, this is used during resolution is
21 + * carried out and line/character position in line is required to point
22 + * out the error location in YANG file.
23 + */
24 +public interface LocationInfo {
25 +
26 + /**
27 + * Returns the line number YANG construct in file.
28 + *
29 + * @return the line number YANG construct in file
30 + */
31 + int getLineNumber();
32 +
33 + /**
34 + * Returns the character position in line.
35 + *
36 + * @return the character position in line
37 + */
38 + int getCharPosition();
39 +
40 + /**
41 + * Sets line number of YANG construct.
42 + *
43 + * @param lineNumber the line number of YANG construct in file
44 + */
45 + void setLineNumber(int lineNumber);
46 +
47 + /**
48 + * Sets character position of YANG construct.
49 + *
50 + * @param charPositionInLine character position of YANG construct in file
51 + */
52 + void setCharPosition(int charPositionInLine);
53 +}
...@@ -228,7 +228,7 @@ public enum YangDataTypes { ...@@ -228,7 +228,7 @@ public enum YangDataTypes {
228 public static YangDataTypes getType(String name) { 228 public static YangDataTypes getType(String name) {
229 name = name.replace("\"", ""); 229 name = name.replace("\"", "");
230 for (YangDataTypes yangDataType : values()) { 230 for (YangDataTypes yangDataType : values()) {
231 - if (yangDataType.name().equalsIgnoreCase(name)) { 231 + if (yangDataType.name().toLowerCase().equals(name)) {
232 return yangDataType; 232 return yangDataType;
233 } 233 }
234 } 234 }
......
...@@ -46,6 +46,7 @@ import java.util.List; ...@@ -46,6 +46,7 @@ import java.util.List;
46 * | reference | 7.19.4 | 0..1 | 46 * | reference | 7.19.4 | 0..1 |
47 * +---------------+---------+-------------+ 47 * +---------------+---------+-------------+
48 */ 48 */
49 +
49 /** 50 /**
50 * Represents pattern restriction information. The regular expression restriction on string 51 * Represents pattern restriction information. The regular expression restriction on string
51 * data type. 52 * data type.
...@@ -58,11 +59,6 @@ public class YangPatternRestriction { ...@@ -58,11 +59,6 @@ public class YangPatternRestriction {
58 private List<String> patternList; 59 private List<String> patternList;
59 60
60 /** 61 /**
61 - * Effective pattern restriction that needs inherited from base type.
62 - */
63 - private List<String> basePattern;
64 -
65 - /**
66 * Creates a YANG pattern restriction object. 62 * Creates a YANG pattern restriction object.
67 */ 63 */
68 public YangPatternRestriction() { 64 public YangPatternRestriction() {
...@@ -95,22 +91,4 @@ public class YangPatternRestriction { ...@@ -95,22 +91,4 @@ public class YangPatternRestriction {
95 public void addPattern(String newPattern) { 91 public void addPattern(String newPattern) {
96 getPatternList().add(newPattern); 92 getPatternList().add(newPattern);
97 } 93 }
98 -
99 - /**
100 - * Returns the pattern restriction defined in base type.
101 - *
102 - * @return pattern restriction defined in base type.
103 - */
104 - public List<String> getBasePattern() {
105 - return basePattern;
106 - }
107 -
108 - /**
109 - * Sets the pattern restriction defined in base type.
110 - *
111 - * @param basePattern pattern restriction defined in base type.
112 - */
113 - public void setBasePattern(List<String> basePattern) {
114 - this.basePattern = basePattern;
115 - }
116 } 94 }
......
...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.datamodel; ...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.datamodel;
18 18
19 import java.util.LinkedList; 19 import java.util.LinkedList;
20 import java.util.List; 20 import java.util.List;
21 -
22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo; 22 import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo;
24 23
...@@ -111,8 +110,8 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> ...@@ -111,8 +110,8 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
111 /** 110 /**
112 * Returns the minimum valid value as per the restriction. 111 * Returns the minimum valid value as per the restriction.
113 * 112 *
114 - * @throws DataModelException data model exception for minimum restriction
115 * @return minimum restricted value 113 * @return minimum restricted value
114 + * @throws DataModelException data model exception for minimum restriction
116 */ 115 */
117 public T getMinRestrictedvalue() throws DataModelException { 116 public T getMinRestrictedvalue() throws DataModelException {
118 if (getAscendingRangeIntervals() == null) { 117 if (getAscendingRangeIntervals() == null) {
...@@ -127,8 +126,8 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> ...@@ -127,8 +126,8 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
127 /** 126 /**
128 * Returns the maximum valid value as per the restriction. 127 * Returns the maximum valid value as per the restriction.
129 * 128 *
130 - * @throws DataModelException data model exception for maximum restriction
131 * @return minimum maximum value 129 * @return minimum maximum value
130 + * @throws DataModelException data model exception for maximum restriction
132 */ 131 */
133 public T getMaxRestrictedvalue() throws DataModelException { 132 public T getMaxRestrictedvalue() throws DataModelException {
134 if (getAscendingRangeIntervals() == null) { 133 if (getAscendingRangeIntervals() == null) {
...@@ -175,7 +174,7 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> ...@@ -175,7 +174,7 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
175 } 174 }
176 175
177 /** 176 /**
178 - * Check if the given value is correct as per the restriction. 177 + * Validates if the given value is correct as per the restriction.
179 * 178 *
180 * @param valueInString value 179 * @param valueInString value
181 * @return true, if the value is confirming to restriction, false otherwise 180 * @return true, if the value is confirming to restriction, false otherwise
...@@ -206,6 +205,32 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> ...@@ -206,6 +205,32 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
206 } 205 }
207 206
208 /** 207 /**
208 + * Validates if the given interval is correct as per the restriction.
209 + *
210 + * @param rangeInterval range interval
211 + * @return true, if the interval is confirming to restriction, false otherwise
212 + * @throws DataModelException data model error
213 + */
214 + public boolean isValidInterval(YangRangeInterval rangeInterval) throws DataModelException {
215 +
216 + if (getAscendingRangeIntervals() == null
217 + || getAscendingRangeIntervals().isEmpty()) {
218 + // Throw exception, At least one default range needs to be set in constructor or in linker.
219 + throw new DataModelException("Range interval missing in range restriction.");
220 + }
221 +
222 + for (YangRangeInterval<T> interval : getAscendingRangeIntervals()) {
223 + int rangeStartCompareRes = interval.getStartValue().compareTo((T) rangeInterval.getStartValue());
224 + int rangeEndCompareRes = interval.getEndValue().compareTo((T) rangeInterval.getEndValue());
225 +
226 + if (rangeStartCompareRes <= 0 && rangeEndCompareRes >= 0) {
227 + return true;
228 + }
229 + }
230 + throw new DataModelException("Range interval doesn't fall within the referred restriction ranges");
231 + }
232 +
233 + /**
209 * Returns the textual reference of the length restriction. 234 * Returns the textual reference of the length restriction.
210 * 235 *
211 * @return textual reference of the length restriction 236 * @return textual reference of the length restriction
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
17 package org.onosproject.yangutils.datamodel; 17 package org.onosproject.yangutils.datamodel;
18 18
19 import java.util.Stack; 19 import java.util.Stack;
20 -
21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 20 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
22 21
23 import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED; 22 import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED;
...@@ -30,7 +29,7 @@ import static org.onosproject.yangutils.datamodel.ResolvableStatus.UNRESOLVED; ...@@ -30,7 +29,7 @@ import static org.onosproject.yangutils.datamodel.ResolvableStatus.UNRESOLVED;
30 * 29 *
31 * @param <T> type of resolution entity uses / type 30 * @param <T> type of resolution entity uses / type
32 */ 31 */
33 -public class YangResolutionInfo<T> { 32 +public class YangResolutionInfo<T> implements LocationInfo {
34 33
35 /** 34 /**
36 * Information about the entity that needs to be resolved. 35 * Information about the entity that needs to be resolved.
...@@ -64,9 +63,9 @@ public class YangResolutionInfo<T> { ...@@ -64,9 +63,9 @@ public class YangResolutionInfo<T> {
64 /** 63 /**
65 * Creates a resolution information object with all the inputs. 64 * Creates a resolution information object with all the inputs.
66 * 65 *
67 - * @param dataNode current parsable data node 66 + * @param dataNode current parsable data node
68 - * @param holderNode parent YANG node 67 + * @param holderNode parent YANG node
69 - * @param lineNumber error line number 68 + * @param lineNumber error line number
70 * @param charPositionInLine error character position in line 69 * @param charPositionInLine error character position in line
71 */ 70 */
72 public YangResolutionInfo(T dataNode, YangNode holderNode, int lineNumber, int charPositionInLine) { 71 public YangResolutionInfo(T dataNode, YangNode holderNode, int lineNumber, int charPositionInLine) {
...@@ -193,7 +192,6 @@ public class YangResolutionInfo<T> { ...@@ -193,7 +192,6 @@ public class YangResolutionInfo<T> {
193 private void resolveTopOfStack() 192 private void resolveTopOfStack()
194 throws DataModelException { 193 throws DataModelException {
195 ((Resolvable) getCurrentEntityToResolveFromStack()).resolve(); 194 ((Resolvable) getCurrentEntityToResolveFromStack()).resolve();
196 -
197 if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() 195 if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus()
198 != INTRA_FILE_RESOLVED) { 196 != INTRA_FILE_RESOLVED) {
199 // Sets the resolution status in inside the type/uses. 197 // Sets the resolution status in inside the type/uses.
...@@ -453,42 +451,6 @@ public class YangResolutionInfo<T> { ...@@ -453,42 +451,6 @@ public class YangResolutionInfo<T> {
453 } 451 }
454 452
455 /** 453 /**
456 - * Returns error position.
457 - *
458 - * @return error position
459 - */
460 - public int getCharPosition() {
461 - return charPosition;
462 - }
463 -
464 - /**
465 - * Sets error position.
466 - *
467 - * @param charPosition position of error
468 - */
469 - public void setCharPosition(int charPosition) {
470 - this.charPosition = charPosition;
471 - }
472 -
473 - /**
474 - * Returns error character position in line.
475 - *
476 - * @return error character position in line
477 - */
478 - public int getLineNumber() {
479 - return lineNumber;
480 - }
481 -
482 - /**
483 - * Sets error character position in line.
484 - *
485 - * @param lineNumber error character position in line
486 - */
487 - public void setLineNumber(int lineNumber) {
488 - this.lineNumber = lineNumber;
489 - }
490 -
491 - /**
492 * Returns stack of YANG type with partially resolved YANG construct 454 * Returns stack of YANG type with partially resolved YANG construct
493 * hierarchy. 455 * hierarchy.
494 * 456 *
...@@ -539,9 +501,29 @@ public class YangResolutionInfo<T> { ...@@ -539,9 +501,29 @@ public class YangResolutionInfo<T> {
539 * Sets information about the entity that needs to be resolved. 501 * Sets information about the entity that needs to be resolved.
540 * 502 *
541 * @param entityToResolveInfo information about the entity that needs to be 503 * @param entityToResolveInfo information about the entity that needs to be
542 - * resolved 504 + * resolved
543 */ 505 */
544 public void setEntityToResolveInfo(YangEntityToResolveInfo<T> entityToResolveInfo) { 506 public void setEntityToResolveInfo(YangEntityToResolveInfo<T> entityToResolveInfo) {
545 this.entityToResolveInfo = entityToResolveInfo; 507 this.entityToResolveInfo = entityToResolveInfo;
546 } 508 }
509 +
510 + @Override
511 + public int getLineNumber() {
512 + return lineNumber;
513 + }
514 +
515 + @Override
516 + public int getCharPosition() {
517 + return charPosition;
518 + }
519 +
520 + @Override
521 + public void setLineNumber(int lineNumber) {
522 + this.lineNumber = lineNumber;
523 + }
524 +
525 + @Override
526 + public void setCharPosition(int charPositionInLine) {
527 + this.charPosition = charPositionInLine;
528 + }
547 } 529 }
......
...@@ -24,6 +24,7 @@ import org.onosproject.yangutils.utils.builtindatatype.YangUint64; ...@@ -24,6 +24,7 @@ import org.onosproject.yangutils.utils.builtindatatype.YangUint64;
24 * A string can be restricted with the "length" and "pattern" statements. 24 * A string can be restricted with the "length" and "pattern" statements.
25 * 25 *
26 */ 26 */
27 +
27 /** 28 /**
28 * Represents the restriction for string data type. 29 * Represents the restriction for string data type.
29 */ 30 */
...@@ -113,7 +114,7 @@ public class YangStringRestriction { ...@@ -113,7 +114,7 @@ public class YangStringRestriction {
113 * 114 *
114 * @param patternRestriction pattern restriction for the type 115 * @param patternRestriction pattern restriction for the type
115 */ 116 */
116 - private void setPatternRestriction(YangPatternRestriction patternRestriction) { 117 + public void setPatternRestriction(YangPatternRestriction patternRestriction) {
117 this.patternRestriction = patternRestriction; 118 this.patternRestriction = patternRestriction;
118 } 119 }
119 120
......
...@@ -20,7 +20,6 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException; ...@@ -20,7 +20,6 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
20 import org.onosproject.yangutils.parser.Parsable; 20 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;
24 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; 23 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
25 24
26 /* 25 /*
...@@ -78,18 +77,6 @@ public class YangType<T> ...@@ -78,18 +77,6 @@ public class YangType<T>
78 private T dataTypeExtendedInfo; 77 private T dataTypeExtendedInfo;
79 78
80 /** 79 /**
81 - * Effective built-in type, requried in case type of typedef is again a
82 - * derived type. This information is to be added during linking.
83 - */
84 - private YangDataTypes effectiveBuiltInType;
85 -
86 - /**
87 - * Effective pattern restriction, requried in case type of typedef is again
88 - * a derived type. This information is to be added during linking.
89 - */
90 - private YangPatternRestriction effectivePatternRestriction;
91 -
92 - /**
93 * Status of resolution. If completely resolved enum value is "RESOLVED", 80 * Status of resolution. If completely resolved enum value is "RESOLVED",
94 * if not enum value is "UNRESOLVED", in case reference of grouping/typedef 81 * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
95 * is added to uses/type but it's not resolved value of enum should be 82 * is added to uses/type but it's not resolved value of enum should be
...@@ -215,42 +202,6 @@ public class YangType<T> ...@@ -215,42 +202,6 @@ public class YangType<T>
215 } 202 }
216 203
217 /** 204 /**
218 - * Return effective built-in type.
219 - *
220 - * @return effective built-in type
221 - */
222 - public YangDataTypes getEffectiveBuiltInType() {
223 - return effectiveBuiltInType;
224 - }
225 -
226 - /**
227 - * Sets effective built-in type.
228 - *
229 - * @param effectiveBuiltInType effective built-in type
230 - */
231 - public void setEffectiveBuiltInType(YangDataTypes effectiveBuiltInType) {
232 - this.effectiveBuiltInType = effectiveBuiltInType;
233 - }
234 -
235 - /**
236 - * Returns effective pattern restriction.
237 - *
238 - * @return effective pattern restriction
239 - */
240 - public YangPatternRestriction getEffectivePatternRestriction() {
241 - return effectivePatternRestriction;
242 - }
243 -
244 - /**
245 - * Sets effective pattern restriction.
246 - *
247 - * @param effectivePatternRestriction effective pattern restriction
248 - */
249 - public void setEffectivePatternRestriction(YangPatternRestriction effectivePatternRestriction) {
250 - this.effectivePatternRestriction = effectivePatternRestriction;
251 - }
252 -
253 - /**
254 * Returns the type of the parsed data. 205 * Returns the type of the parsed data.
255 * 206 *
256 * @return returns TYPE_DATA 207 * @return returns TYPE_DATA
...@@ -269,7 +220,6 @@ public class YangType<T> ...@@ -269,7 +220,6 @@ public class YangType<T>
269 public void validateDataOnEntry() 220 public void validateDataOnEntry()
270 throws DataModelException { 221 throws DataModelException {
271 // TODO auto-generated method stub, to be implemented by parser 222 // TODO auto-generated method stub, to be implemented by parser
272 -
273 } 223 }
274 224
275 /** 225 /**
...@@ -281,7 +231,6 @@ public class YangType<T> ...@@ -281,7 +231,6 @@ public class YangType<T>
281 public void validateDataOnExit() 231 public void validateDataOnExit()
282 throws DataModelException { 232 throws DataModelException {
283 // TODO auto-generated method stub, to be implemented by parser 233 // TODO auto-generated method stub, to be implemented by parser
284 -
285 } 234 }
286 235
287 @Override 236 @Override
...@@ -297,17 +246,19 @@ public class YangType<T> ...@@ -297,17 +246,19 @@ public class YangType<T>
297 @Override 246 @Override
298 public void resolve() throws DataModelException { 247 public void resolve() throws DataModelException {
299 /* 248 /*
300 - Inherit the Restriction from the referred typedef definition. 249 + * Check whether the data type is derived.
301 */ 250 */
302 if (getDataType() != DERIVED) { 251 if (getDataType() != DERIVED) {
303 - throw new DataModelException("Resolve should only be called for derived data types"); 252 + throw new DataModelException("Linker Error: Resolve should only be called for derived data types.");
304 } 253 }
305 254
306 - YangDerivedInfo<?> derrivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo(); 255 + // Check if the derived info is present.
307 - YangType<?> baseType = derrivedInfo.getReferredTypeDef().getTypeDefBaseType(); 256 + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo();
308 - if (DERIVED == baseType.getDataType() && baseType.getResolvableStatus() == INTRA_FILE_RESOLVED) { 257 + if (derivedInfo == null) {
309 - setResolvableStatus(INTRA_FILE_RESOLVED); 258 + throw new DataModelException("Linker Error: Derived information is missing.");
310 } 259 }
311 - //TODO: 260 +
261 + // Initiate the resolution
262 + setResolvableStatus(derivedInfo.resolve());
312 } 263 }
313 } 264 }
......
...@@ -83,11 +83,6 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, Y ...@@ -83,11 +83,6 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, Y
83 private String name; 83 private String name;
84 84
85 /** 85 /**
86 - * Maintain the data type information.
87 - */
88 - private YangType<?> dataType;
89 -
90 - /**
91 * Units of the data type. 86 * Units of the data type.
92 */ 87 */
93 private String units; 88 private String units;
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -16,34 +16,26 @@ ...@@ -16,34 +16,26 @@
16 16
17 package org.onosproject.yangutils.parser.impl.listeners; 17 package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 -import java.util.regex.Pattern; 19 +import org.onosproject.yangutils.datamodel.YangDataTypes;
20 - 20 +import org.onosproject.yangutils.datamodel.YangDerivedInfo;
21 import org.onosproject.yangutils.datamodel.YangRangeRestriction; 21 import org.onosproject.yangutils.datamodel.YangRangeRestriction;
22 -import org.onosproject.yangutils.datamodel.YangRangeInterval;
23 import org.onosproject.yangutils.datamodel.YangStringRestriction; 22 import org.onosproject.yangutils.datamodel.YangStringRestriction;
24 import org.onosproject.yangutils.datamodel.YangType; 23 import org.onosproject.yangutils.datamodel.YangType;
25 -import org.onosproject.yangutils.datamodel.YangDataTypes;
26 -import org.onosproject.yangutils.datamodel.YangDerivedInfo;
27 -import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
28 import org.onosproject.yangutils.parser.Parsable; 24 import org.onosproject.yangutils.parser.Parsable;
29 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 25 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
30 import org.onosproject.yangutils.parser.exceptions.ParserException; 26 import org.onosproject.yangutils.parser.exceptions.ParserException;
31 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 27 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
32 import org.onosproject.yangutils.utils.YangConstructType; 28 import org.onosproject.yangutils.utils.YangConstructType;
33 -import org.onosproject.yangutils.utils.builtindatatype.DataTypeException;
34 -import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo;
35 29
36 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; 30 +import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
37 -import static org.onosproject.yangutils.utils.YangConstructType.LENGTH_DATA;
38 -import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
40 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
41 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
42 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
43 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
44 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
45 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 35 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
46 -import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString; 36 +import static org.onosproject.yangutils.utils.RestrictionResolver.processLengthRestriction;
37 +import static org.onosproject.yangutils.utils.YangConstructType.LENGTH_DATA;
38 +import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
47 39
48 /* 40 /*
49 * Reference: RFC6020 and YANG ANTLR Grammar 41 * Reference: RFC6020 and YANG ANTLR Grammar
...@@ -71,11 +63,6 @@ import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectF ...@@ -71,11 +63,6 @@ import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectF
71 */ 63 */
72 public final class LengthRestrictionListener { 64 public final class LengthRestrictionListener {
73 65
74 - private static final String PIPE = "|";
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;
78 -
79 /** 66 /**
80 * Creates a new length restriction listener. 67 * Creates a new length restriction listener.
81 */ 68 */
...@@ -88,10 +75,10 @@ public final class LengthRestrictionListener { ...@@ -88,10 +75,10 @@ public final class LengthRestrictionListener {
88 * tree. 75 * tree.
89 * 76 *
90 * @param listener listener's object 77 * @param listener listener's object
91 - * @param ctx context object of the grammar rule 78 + * @param ctx context object of the grammar rule
92 */ 79 */
93 public static void processLengthRestrictionEntry(TreeWalkListener listener, 80 public static void processLengthRestrictionEntry(TreeWalkListener listener,
94 - GeneratedYangParser.LengthStatementContext ctx) { 81 + GeneratedYangParser.LengthStatementContext ctx) {
95 82
96 // Check for stack to be non empty. 83 // Check for stack to be non empty.
97 checkStackIsNotEmpty(listener, MISSING_HOLDER, LENGTH_DATA, ctx.length().getText(), ENTRY); 84 checkStackIsNotEmpty(listener, MISSING_HOLDER, LENGTH_DATA, ctx.length().getText(), ENTRY);
...@@ -110,18 +97,22 @@ public final class LengthRestrictionListener { ...@@ -110,18 +97,22 @@ public final class LengthRestrictionListener {
110 * Sets the length restriction to type. 97 * Sets the length restriction to type.
111 * 98 *
112 * @param type Yang type for which length restriction to be set 99 * @param type Yang type for which length restriction to be set
113 - * @param ctx context object of the grammar rule 100 + * @param ctx context object of the grammar rule
114 */ 101 */
115 private static void setLengthRestriction(YangType type, 102 private static void setLengthRestriction(YangType type,
116 - GeneratedYangParser.LengthStatementContext ctx) { 103 + GeneratedYangParser.LengthStatementContext ctx) {
117 - 104 +
118 - YangStringRestriction stringRestriction; 105 + if (type.getDataType() == DERIVED) {
119 - YangBuiltInDataTypeInfo<?> startValue; 106 + ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
120 - YangBuiltInDataTypeInfo<?> endValue; 107 + .setLengthRestrictionString(ctx.length().getText());
121 - YangRangeRestriction lengthRestriction = new YangRangeRestriction<>(); 108 + ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
122 - 109 + .setLineNumber(ctx.getStart().getLine());
123 - if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) { 110 + ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
111 + .setCharPosition(ctx.getStart().getCharPositionInLine());
112 + return;
113 + }
124 114
115 + if (type.getDataType() != YangDataTypes.STRING) {
125 ParserException parserException = new ParserException("YANG file error : " + 116 ParserException parserException = new ParserException("YANG file error : " +
126 YangConstructType.getYangConstructType(LENGTH_DATA) + " name " + ctx.length().getText() + 117 YangConstructType.getYangConstructType(LENGTH_DATA) + " name " + ctx.length().getText() +
127 " can be used to restrict the built-in type string or types derived from string."); 118 " can be used to restrict the built-in type string or types derived from string.");
...@@ -130,71 +121,14 @@ public final class LengthRestrictionListener { ...@@ -130,71 +121,14 @@ public final class LengthRestrictionListener {
130 throw parserException; 121 throw parserException;
131 } 122 }
132 123
133 - if (type.getDataType() == YangDataTypes.STRING) { 124 + YangRangeRestriction lengthRestriction = processLengthRestriction(null, ctx.getStart().getLine(),
134 - stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo(); 125 + ctx.getStart().getCharPositionInLine(), false, ctx.length().getText());
135 - } else { 126 +
136 - stringRestriction = (YangStringRestriction) ((YangDerivedInfo<?>) type 127 + YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
137 - .getDataTypeExtendedInfo()).getExtendedInfo();
138 - }
139 128
140 if (stringRestriction == null) { 129 if (stringRestriction == null) {
141 stringRestriction = new YangStringRestriction(); 130 stringRestriction = new YangStringRestriction();
142 - if (type.getDataType() == YangDataTypes.STRING) { 131 + type.setDataTypeExtendedInfo(stringRestriction);
143 - type.setDataTypeExtendedInfo(stringRestriction);
144 - } else {
145 - ((YangDerivedInfo<YangStringRestriction>) type.getDataTypeExtendedInfo())
146 - .setExtendedInfo(stringRestriction);
147 - }
148 - }
149 -
150 - String rangeArgument = removeQuotesAndHandleConcat(ctx.length().getText());
151 - String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
152 -
153 - for (String rangePart : rangeArguments) {
154 - String startInterval;
155 - String endInterval;
156 - YangRangeInterval rangeInterval = new YangRangeInterval<>();
157 - String[] rangeBoundary = rangePart.trim().split(Pattern.quote(LENGTH_INTERVAL));
158 -
159 - if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
160 - ParserException parserException = new ParserException("YANG file error : " +
161 - YangConstructType.getYangConstructType(LENGTH_DATA) + " " + rangeArgument +
162 - " is not valid.");
163 - parserException.setLine(ctx.getStart().getLine());
164 - parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
165 - throw parserException;
166 - }
167 -
168 - if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
169 - startInterval = rangeBoundary[0];
170 - endInterval = rangeBoundary[0];
171 - } else {
172 - startInterval = rangeBoundary[0];
173 - endInterval = rangeBoundary[1];
174 - }
175 -
176 - try {
177 - startValue = getDataObjectFromString(startInterval, YangDataTypes.UINT64);
178 - endValue = getDataObjectFromString(endInterval, YangDataTypes.UINT64);
179 - } catch (DataTypeException e) {
180 - ParserException parserException = new ParserException(e.getMessage());
181 - parserException.setLine(ctx.getStart().getLine());
182 - parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
183 - throw parserException;
184 - }
185 -
186 - rangeInterval.setStartValue(startValue);
187 - rangeInterval.setEndValue(endValue);
188 -
189 - try {
190 - lengthRestriction.addRangeRestrictionInterval(rangeInterval);
191 - } catch (DataModelException e) {
192 - ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
193 - UNHANDLED_PARSED_DATA, LENGTH_DATA, rangeArgument, ENTRY, e.getMessage()));
194 - parserException.setLine(ctx.getStart().getLine());
195 - parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
196 - throw parserException;
197 - }
198 } 132 }
199 133
200 stringRestriction.setLengthRestriction(lengthRestriction); 134 stringRestriction.setLengthRestriction(lengthRestriction);
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -16,23 +16,24 @@ ...@@ -16,23 +16,24 @@
16 16
17 package org.onosproject.yangutils.parser.impl.listeners; 17 package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 +import org.onosproject.yangutils.datamodel.YangDataTypes;
19 import org.onosproject.yangutils.datamodel.YangDerivedInfo; 20 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
20 -import org.onosproject.yangutils.datamodel.YangType; 21 +import org.onosproject.yangutils.datamodel.YangPatternRestriction;
21 import org.onosproject.yangutils.datamodel.YangStringRestriction; 22 import org.onosproject.yangutils.datamodel.YangStringRestriction;
22 -import org.onosproject.yangutils.datamodel.YangDataTypes; 23 +import org.onosproject.yangutils.datamodel.YangType;
23 import org.onosproject.yangutils.parser.Parsable; 24 import org.onosproject.yangutils.parser.Parsable;
24 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 25 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
25 import org.onosproject.yangutils.parser.exceptions.ParserException; 26 import org.onosproject.yangutils.parser.exceptions.ParserException;
26 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 27 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
27 import org.onosproject.yangutils.utils.YangConstructType; 28 import org.onosproject.yangutils.utils.YangConstructType;
28 29
29 -import static org.onosproject.yangutils.utils.YangConstructType.PATTERN_DATA;
30 -import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 33 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
35 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 34 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
35 +import static org.onosproject.yangutils.utils.YangConstructType.PATTERN_DATA;
36 +import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
36 37
37 /* 38 /*
38 * Reference: RFC6020 and YANG ANTLR Grammar 39 * Reference: RFC6020 and YANG ANTLR Grammar
...@@ -72,10 +73,10 @@ public final class PatternRestrictionListener { ...@@ -72,10 +73,10 @@ public final class PatternRestrictionListener {
72 * tree. 73 * tree.
73 * 74 *
74 * @param listener listener's object 75 * @param listener listener's object
75 - * @param ctx context object of the grammar rule 76 + * @param ctx context object of the grammar rule
76 */ 77 */
77 public static void processPatternRestrictionEntry(TreeWalkListener listener, 78 public static void processPatternRestrictionEntry(TreeWalkListener listener,
78 - GeneratedYangParser.PatternStatementContext ctx) { 79 + GeneratedYangParser.PatternStatementContext ctx) {
79 80
80 // Check for stack to be non empty. 81 // Check for stack to be non empty.
81 checkStackIsNotEmpty(listener, MISSING_HOLDER, PATTERN_DATA, ctx.string().getText(), ENTRY); 82 checkStackIsNotEmpty(listener, MISSING_HOLDER, PATTERN_DATA, ctx.string().getText(), ENTRY);
...@@ -94,13 +95,11 @@ public final class PatternRestrictionListener { ...@@ -94,13 +95,11 @@ public final class PatternRestrictionListener {
94 * Sets the pattern restriction to type. 95 * Sets the pattern restriction to type.
95 * 96 *
96 * @param type Yang type for which pattern restriction to be set 97 * @param type Yang type for which pattern restriction to be set
97 - * @param ctx context object of the grammar rule 98 + * @param ctx context object of the grammar rule
98 */ 99 */
99 private static void setPatternRestriction(YangType type, 100 private static void setPatternRestriction(YangType type,
100 GeneratedYangParser.PatternStatementContext ctx) { 101 GeneratedYangParser.PatternStatementContext ctx) {
101 102
102 - YangStringRestriction stringRestriction;
103 -
104 if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) { 103 if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) {
105 104
106 ParserException parserException = new ParserException("YANG file error : " + 105 ParserException parserException = new ParserException("YANG file error : " +
...@@ -111,24 +110,28 @@ public final class PatternRestrictionListener { ...@@ -111,24 +110,28 @@ public final class PatternRestrictionListener {
111 throw parserException; 110 throw parserException;
112 } 111 }
113 112
114 - if (type.getDataType() == YangDataTypes.STRING) { 113 + String patternArgument = ctx.string().getText().replace("\"", EMPTY_STRING);
115 - stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
116 - } else {
117 - stringRestriction = (YangStringRestriction) ((YangDerivedInfo<?>) type
118 - .getDataTypeExtendedInfo()).getExtendedInfo();
119 - }
120 114
121 - if (stringRestriction == null) { 115 + if (type.getDataType() == YangDataTypes.STRING) {
122 - stringRestriction = new YangStringRestriction(); 116 + YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
123 - if (type.getDataType() == YangDataTypes.STRING) { 117 + if (stringRestriction == null) {
118 + stringRestriction = new YangStringRestriction();
124 type.setDataTypeExtendedInfo(stringRestriction); 119 type.setDataTypeExtendedInfo(stringRestriction);
120 + stringRestriction.addPattern(patternArgument);
125 } else { 121 } else {
126 - ((YangDerivedInfo<YangStringRestriction>) type.getDataTypeExtendedInfo()) 122 + stringRestriction.addPattern(patternArgument);
127 - .setExtendedInfo(stringRestriction); 123 + }
124 + } else {
125 + YangPatternRestriction patternRestriction = (YangPatternRestriction) ((YangDerivedInfo<?>) type
126 + .getDataTypeExtendedInfo()).getPatternRestriction();
127 + if (patternRestriction == null) {
128 + patternRestriction = new YangPatternRestriction();
129 + ((YangDerivedInfo<?>) type.getDataTypeExtendedInfo()).setPatternRestriction(patternRestriction);
130 + patternRestriction.addPattern(patternArgument);
131 + } else {
132 + ((YangDerivedInfo<?>) type.getDataTypeExtendedInfo()).setPatternRestriction(patternRestriction);
133 + patternRestriction.addPattern(patternArgument);
128 } 134 }
129 } 135 }
130 -
131 - String patternArgument = ctx.string().getText().replace("\"", EMPTY_STRING);
132 - stringRestriction.addPattern(patternArgument);
133 } 136 }
134 } 137 }
......
...@@ -16,33 +16,24 @@ ...@@ -16,33 +16,24 @@
16 16
17 package org.onosproject.yangutils.parser.impl.listeners; 17 package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 -import java.util.regex.Pattern; 19 +import org.onosproject.yangutils.datamodel.YangDerivedInfo;
20 -
21 -import org.onosproject.yangutils.datamodel.YangRangeInterval;
22 import org.onosproject.yangutils.datamodel.YangRangeRestriction; 20 import org.onosproject.yangutils.datamodel.YangRangeRestriction;
23 import org.onosproject.yangutils.datamodel.YangType; 21 import org.onosproject.yangutils.datamodel.YangType;
24 -import org.onosproject.yangutils.datamodel.YangDerivedInfo;
25 -import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
26 -import org.onosproject.yangutils.datamodel.YangDataTypes;
27 import org.onosproject.yangutils.parser.Parsable; 22 import org.onosproject.yangutils.parser.Parsable;
28 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 23 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
29 import org.onosproject.yangutils.parser.exceptions.ParserException; 24 import org.onosproject.yangutils.parser.exceptions.ParserException;
30 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 25 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
31 -import org.onosproject.yangutils.utils.YangConstructType;
32 -import org.onosproject.yangutils.utils.builtindatatype.DataTypeException;
33 -import org.onosproject.yangutils.utils.builtindatatype.YangBuiltInDataTypeInfo;
34 26
27 +import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
35 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
36 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
37 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 29 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
38 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; 30 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
39 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
40 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
41 -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
42 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; 32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
43 -import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA; 33 +import static org.onosproject.yangutils.utils.RestrictionResolver.isOfRangeRestrictedType;
34 +import static org.onosproject.yangutils.utils.RestrictionResolver.processRangeRestriction;
44 import static org.onosproject.yangutils.utils.YangConstructType.RANGE_DATA; 35 import static org.onosproject.yangutils.utils.YangConstructType.RANGE_DATA;
45 -import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString; 36 +import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
46 37
47 /* 38 /*
48 * Reference: RFC6020 and YANG ANTLR Grammar 39 * Reference: RFC6020 and YANG ANTLR Grammar
...@@ -68,11 +59,6 @@ import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectF ...@@ -68,11 +59,6 @@ import static org.onosproject.yangutils.utils.builtindatatype.BuiltInTypeObjectF
68 */ 59 */
69 public final class RangeRestrictionListener { 60 public final class RangeRestrictionListener {
70 61
71 - private static final String PIPE = "|";
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;
75 -
76 /** 62 /**
77 * Creates a new range restriction listener. 63 * Creates a new range restriction listener.
78 */ 64 */
...@@ -85,10 +71,10 @@ public final class RangeRestrictionListener { ...@@ -85,10 +71,10 @@ public final class RangeRestrictionListener {
85 * tree. 71 * tree.
86 * 72 *
87 * @param listener listener's object 73 * @param listener listener's object
88 - * @param ctx context object of the grammar rule 74 + * @param ctx context object of the grammar rule
89 */ 75 */
90 public static void processRangeRestrictionEntry(TreeWalkListener listener, 76 public static void processRangeRestrictionEntry(TreeWalkListener listener,
91 - GeneratedYangParser.RangeStatementContext ctx) { 77 + GeneratedYangParser.RangeStatementContext ctx) {
92 78
93 // Check for stack to be non empty. 79 // Check for stack to be non empty.
94 checkStackIsNotEmpty(listener, MISSING_HOLDER, RANGE_DATA, ctx.range().getText(), ENTRY); 80 checkStackIsNotEmpty(listener, MISSING_HOLDER, RANGE_DATA, ctx.range().getText(), ENTRY);
...@@ -107,73 +93,34 @@ public final class RangeRestrictionListener { ...@@ -107,73 +93,34 @@ public final class RangeRestrictionListener {
107 * Sets the range restriction to type. 93 * Sets the range restriction to type.
108 * 94 *
109 * @param type YANG type for which range restriction to be added 95 * @param type YANG type for which range restriction to be added
110 - * @param ctx context object of the grammar rule 96 + * @param ctx context object of the grammar rule
111 */ 97 */
112 private static void setRangeRestriction(YangType type, 98 private static void setRangeRestriction(YangType type,
113 - GeneratedYangParser.RangeStatementContext ctx) { 99 + GeneratedYangParser.RangeStatementContext ctx) {
114 - 100 +
115 - YangBuiltInDataTypeInfo<?> startValue; 101 + if (type.getDataType() == DERIVED) {
116 - YangBuiltInDataTypeInfo<?> endValue; 102 + ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
117 - YangRangeRestriction rangeRestriction = new YangRangeRestriction(); 103 + .setRangeRestrictionString(ctx.range().getText());
118 - 104 + ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
119 - String rangeArgument = removeQuotesAndHandleConcat(ctx.range().getText()); 105 + .setLineNumber(ctx.getStart().getLine());
120 - String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE)); 106 + ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
121 - 107 + .setCharPosition(ctx.getStart().getCharPositionInLine());
122 - for (String rangePart : rangeArguments) { 108 + return;
123 - String startInterval; 109 + }
124 - String endInterval;
125 - YangRangeInterval rangeInterval = new YangRangeInterval();
126 - String[] rangeBoundary = rangePart.trim().split(Pattern.quote(RANGE_INTERVAL));
127 -
128 - if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
129 - ParserException parserException = new ParserException("YANG file error : " +
130 - YangConstructType.getYangConstructType(RANGE_DATA) + " " + rangeArgument +
131 - " is not valid.");
132 - parserException.setLine(ctx.getStart().getLine());
133 - parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
134 - throw parserException;
135 - }
136 -
137 - if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
138 - startInterval = rangeBoundary[0];
139 - endInterval = rangeBoundary[0];
140 - } else {
141 - startInterval = rangeBoundary[0];
142 - endInterval = rangeBoundary[1];
143 - }
144 -
145 - try {
146 - startValue = getDataObjectFromString(startInterval, type.getDataType());
147 - endValue = getDataObjectFromString(endInterval, type.getDataType());
148 - } catch (DataTypeException e) {
149 - ParserException parserException = new ParserException(e.getMessage());
150 - parserException.setLine(ctx.getStart().getLine());
151 - parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
152 - throw parserException;
153 - }
154 -
155 - rangeInterval.setStartValue(startValue);
156 - rangeInterval.setEndValue(endValue);
157 110
158 - try { 111 + if (!(isOfRangeRestrictedType(type.getDataType()))) {
159 - rangeRestriction.addRangeRestrictionInterval(rangeInterval); 112 + ParserException parserException = new ParserException("YANG file error: Range restriction can't be " +
160 - } catch (DataModelException e) { 113 + "applied to a given type");
161 - ParserException parserException = new ParserException(constructExtendedListenerErrorMessage( 114 + parserException.setLine(ctx.getStart().getLine());
162 - UNHANDLED_PARSED_DATA, RANGE_DATA, rangeArgument, ENTRY, e.getMessage())); 115 + parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
163 - parserException.setLine(ctx.getStart().getLine()); 116 + throw parserException;
164 - parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
165 - throw parserException;
166 - }
167 } 117 }
168 118
119 + YangRangeRestriction rangeRestriction = processRangeRestriction(null, ctx.getStart().getLine(),
120 + ctx.getStart().getCharPositionInLine(), false, ctx.range().getText(), type.getDataType());
121 +
169 if (rangeRestriction != null) { 122 if (rangeRestriction != null) {
170 - if (type.getDataType() == YangDataTypes.DERIVED) { 123 + type.setDataTypeExtendedInfo(rangeRestriction);
171 - ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
172 - .setExtendedInfo(rangeRestriction);
173 - } else {
174 - type.setDataTypeExtendedInfo(rangeRestriction);
175 - }
176 } 124 }
177 -
178 } 125 }
179 } 126 }
...\ No newline at end of file ...\ No newline at end of file
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 +
16 package org.onosproject.yangutils.utils.builtindatatype; 17 package org.onosproject.yangutils.utils.builtindatatype;
17 18
18 import org.onosproject.yangutils.datamodel.YangDataTypes; 19 import org.onosproject.yangutils.datamodel.YangDataTypes;
...@@ -66,7 +67,8 @@ public class YangInt16 implements YangBuiltInDataTypeInfo<YangInt16> { ...@@ -66,7 +67,8 @@ public class YangInt16 implements YangBuiltInDataTypeInfo<YangInt16> {
66 try { 67 try {
67 value = Short.parseShort(valueInString); 68 value = Short.parseShort(valueInString);
68 } catch (Exception e) { 69 } catch (Exception e) {
69 - throw new DataTypeException("YANG file error : " + valueInString + " is not valid."); 70 + throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
71 + "int16.");
70 } 72 }
71 } 73 }
72 } 74 }
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 +
16 package org.onosproject.yangutils.utils.builtindatatype; 17 package org.onosproject.yangutils.utils.builtindatatype;
17 18
18 import org.onosproject.yangutils.datamodel.YangDataTypes; 19 import org.onosproject.yangutils.datamodel.YangDataTypes;
...@@ -65,7 +66,8 @@ public class YangInt32 implements YangBuiltInDataTypeInfo<YangInt32> { ...@@ -65,7 +66,8 @@ public class YangInt32 implements YangBuiltInDataTypeInfo<YangInt32> {
65 try { 66 try {
66 value = Integer.parseInt(valueInString); 67 value = Integer.parseInt(valueInString);
67 } catch (Exception e) { 68 } catch (Exception e) {
68 - throw new DataTypeException("YANG file error : " + valueInString + " is not valid."); 69 + throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
70 + "int32.");
69 } 71 }
70 } 72 }
71 } 73 }
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 +
16 package org.onosproject.yangutils.utils.builtindatatype; 17 package org.onosproject.yangutils.utils.builtindatatype;
17 18
18 import org.onosproject.yangutils.datamodel.YangDataTypes; 19 import org.onosproject.yangutils.datamodel.YangDataTypes;
...@@ -65,7 +66,8 @@ public class YangInt64 implements YangBuiltInDataTypeInfo<YangInt64> { ...@@ -65,7 +66,8 @@ public class YangInt64 implements YangBuiltInDataTypeInfo<YangInt64> {
65 try { 66 try {
66 value = Long.parseLong(valueInString); 67 value = Long.parseLong(valueInString);
67 } catch (Exception e) { 68 } catch (Exception e) {
68 - throw new DataTypeException("YANG file error : " + valueInString + " is not valid."); 69 + throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
70 + "int64.");
69 } 71 }
70 } 72 }
71 } 73 }
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 +
16 package org.onosproject.yangutils.utils.builtindatatype; 17 package org.onosproject.yangutils.utils.builtindatatype;
17 18
18 import org.onosproject.yangutils.datamodel.YangDataTypes; 19 import org.onosproject.yangutils.datamodel.YangDataTypes;
...@@ -65,7 +66,8 @@ public class YangInt8 implements YangBuiltInDataTypeInfo<YangInt8> { ...@@ -65,7 +66,8 @@ public class YangInt8 implements YangBuiltInDataTypeInfo<YangInt8> {
65 try { 66 try {
66 value = Byte.parseByte(valueInString); 67 value = Byte.parseByte(valueInString);
67 } catch (Exception e) { 68 } catch (Exception e) {
68 - throw new DataTypeException("YANG file error : " + valueInString + " is not valid."); 69 + throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
70 + "int8.");
69 } 71 }
70 } 72 }
71 } 73 }
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 +
16 package org.onosproject.yangutils.utils.builtindatatype; 17 package org.onosproject.yangutils.utils.builtindatatype;
17 18
18 import org.onosproject.yangutils.datamodel.YangDataTypes; 19 import org.onosproject.yangutils.datamodel.YangDataTypes;
...@@ -65,7 +66,8 @@ public class YangUint16 implements YangBuiltInDataTypeInfo<YangUint16> { ...@@ -65,7 +66,8 @@ public class YangUint16 implements YangBuiltInDataTypeInfo<YangUint16> {
65 try { 66 try {
66 value = Integer.parseInt(valueInString); 67 value = Integer.parseInt(valueInString);
67 } catch (Exception e) { 68 } catch (Exception e) {
68 - throw new DataTypeException("YANG file error : " + valueInString + " is not valid."); 69 + throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
70 + "uint16.");
69 } 71 }
70 } 72 }
71 73
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 +
16 package org.onosproject.yangutils.utils.builtindatatype; 17 package org.onosproject.yangutils.utils.builtindatatype;
17 18
18 import org.onosproject.yangutils.datamodel.YangDataTypes; 19 import org.onosproject.yangutils.datamodel.YangDataTypes;
...@@ -58,7 +59,8 @@ public class YangUint32 implements YangBuiltInDataTypeInfo<YangUint32> { ...@@ -58,7 +59,8 @@ public class YangUint32 implements YangBuiltInDataTypeInfo<YangUint32> {
58 try { 59 try {
59 value = Long.parseLong(valueInString); 60 value = Long.parseLong(valueInString);
60 } catch (Exception e) { 61 } catch (Exception e) {
61 - throw new DataTypeException("YANG file error : " + valueInString + " is not valid."); 62 + throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
63 + "uint32.");
62 } 64 }
63 } 65 }
64 66
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 +
16 package org.onosproject.yangutils.utils.builtindatatype; 17 package org.onosproject.yangutils.utils.builtindatatype;
17 18
18 import java.math.BigInteger; 19 import java.math.BigInteger;
...@@ -71,7 +72,8 @@ public class YangUint64 implements YangBuiltInDataTypeInfo<YangUint64> { ...@@ -71,7 +72,8 @@ public class YangUint64 implements YangBuiltInDataTypeInfo<YangUint64> {
71 } else if (NON_NEGATIVE_INTEGER_PATTERN.matcher(valueInString).matches()) { 72 } else if (NON_NEGATIVE_INTEGER_PATTERN.matcher(valueInString).matches()) {
72 value = new BigInteger(valueInString); 73 value = new BigInteger(valueInString);
73 } else { 74 } else {
74 - throw new DataTypeException("YANG file error : " + valueInString + " is not valid."); 75 + throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
76 + "uint64.");
75 } 77 }
76 78
77 if (value.compareTo(MIN_VALUE) < 0) { 79 if (value.compareTo(MIN_VALUE) < 0) {
......
1 /* 1 /*
2 - * Copyright 2016 Open Networking Laboratory 2 + * Copyright 2016-present Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 +
16 package org.onosproject.yangutils.utils.builtindatatype; 17 package org.onosproject.yangutils.utils.builtindatatype;
17 18
18 import org.onosproject.yangutils.datamodel.YangDataTypes; 19 import org.onosproject.yangutils.datamodel.YangDataTypes;
...@@ -65,7 +66,8 @@ public class YangUint8 implements YangBuiltInDataTypeInfo<YangUint8> { ...@@ -65,7 +66,8 @@ public class YangUint8 implements YangBuiltInDataTypeInfo<YangUint8> {
65 try { 66 try {
66 value = Short.parseShort(valueInString); 67 value = Short.parseShort(valueInString);
67 } catch (Exception e) { 68 } catch (Exception e) {
68 - throw new DataTypeException("YANG file error : " + valueInString + " is not valid."); 69 + throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
70 + "uint8.");
69 } 71 }
70 } 72 }
71 73
......
...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.linker; ...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.linker;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.util.ListIterator; 20 import java.util.ListIterator;
21 -
22 import org.junit.Rule; 21 import org.junit.Rule;
23 import org.junit.Test; 22 import org.junit.Test;
24 import org.junit.rules.ExpectedException; 23 import org.junit.rules.ExpectedException;
...@@ -81,7 +80,7 @@ public class IntraFileUsesLinkingTest { ...@@ -81,7 +80,7 @@ public class IntraFileUsesLinkingTest {
81 80
82 // Check whether the information in the leaf is correct under grouping. 81 // Check whether the information in the leaf is correct under grouping.
83 assertThat(leafInfo.getName(), is("hello")); 82 assertThat(leafInfo.getName(), is("hello"));
84 - assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); 83 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
85 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); 84 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
86 85
87 // Check whether uses is module's child. 86 // Check whether uses is module's child.
...@@ -97,7 +96,7 @@ public class IntraFileUsesLinkingTest { ...@@ -97,7 +96,7 @@ public class IntraFileUsesLinkingTest {
97 96
98 // Check whether the information in the leaf is correct under module. 97 // Check whether the information in the leaf is correct under module.
99 assertThat(leafInfo.getName(), is("hello")); 98 assertThat(leafInfo.getName(), is("hello"));
100 - assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); 99 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
101 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); 100 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
102 101
103 } 102 }
...@@ -135,7 +134,7 @@ public class IntraFileUsesLinkingTest { ...@@ -135,7 +134,7 @@ public class IntraFileUsesLinkingTest {
135 134
136 // Check whether the information in the leaf is correct under grouping. 135 // Check whether the information in the leaf is correct under grouping.
137 assertThat(leafInfo.getName(), is("treat")); 136 assertThat(leafInfo.getName(), is("treat"));
138 - assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); 137 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
139 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); 138 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
140 139
141 // Check whether container is the child of grouping. 140 // Check whether container is the child of grouping.
...@@ -150,7 +149,7 @@ public class IntraFileUsesLinkingTest { ...@@ -150,7 +149,7 @@ public class IntraFileUsesLinkingTest {
150 149
151 // Check whether the information in the leaf is correct under container which is under grouping. 150 // Check whether the information in the leaf is correct under container which is under grouping.
152 assertThat(leafInfo.getName(), is("leaf2")); 151 assertThat(leafInfo.getName(), is("leaf2"));
153 - assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); 152 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
154 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); 153 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
155 154
156 // Check whether uses is module's child. 155 // Check whether uses is module's child.
...@@ -166,7 +165,7 @@ public class IntraFileUsesLinkingTest { ...@@ -166,7 +165,7 @@ public class IntraFileUsesLinkingTest {
166 165
167 // Check whether the information in the leaf is correct under module. 166 // Check whether the information in the leaf is correct under module.
168 assertThat(leafInfo.getName(), is("treat")); 167 assertThat(leafInfo.getName(), is("treat"));
169 - assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); 168 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
170 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); 169 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
171 170
172 // Check whether container is the child of module. 171 // Check whether container is the child of module.
...@@ -181,7 +180,7 @@ public class IntraFileUsesLinkingTest { ...@@ -181,7 +180,7 @@ public class IntraFileUsesLinkingTest {
181 180
182 // Check whether the information in the leaf is correct under container which is under module. 181 // Check whether the information in the leaf is correct under container which is under module.
183 assertThat(leafInfo.getName(), is("leaf2")); 182 assertThat(leafInfo.getName(), is("leaf2"));
184 - assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); 183 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
185 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); 184 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
186 } 185 }
187 186
...@@ -688,7 +687,7 @@ public class IntraFileUsesLinkingTest { ...@@ -688,7 +687,7 @@ public class IntraFileUsesLinkingTest {
688 687
689 // Check whether the information in the leaf is correct under grouping. 688 // Check whether the information in the leaf is correct under grouping.
690 assertThat(leafInfo.getName(), is("hello")); 689 assertThat(leafInfo.getName(), is("hello"));
691 - assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); 690 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
692 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); 691 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
693 692
694 } 693 }
...@@ -762,7 +761,7 @@ public class IntraFileUsesLinkingTest { ...@@ -762,7 +761,7 @@ public class IntraFileUsesLinkingTest {
762 761
763 // Check whether the information in the leaf is correct under grouping. 762 // Check whether the information in the leaf is correct under grouping.
764 assertThat(leafInfo.getName(), is("hello")); 763 assertThat(leafInfo.getName(), is("hello"));
765 - assertThat(leafInfo.getDataType().getDataTypeName(), is("String")); 764 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
766 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); 765 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
767 } 766 }
768 767
......
...@@ -19,20 +19,18 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -19,20 +19,18 @@ package org.onosproject.yangutils.parser.impl.listeners;
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.math.BigInteger; 20 import java.math.BigInteger;
21 import java.util.ListIterator; 21 import java.util.ListIterator;
22 -
23 import org.junit.Rule; 22 import org.junit.Rule;
24 import org.junit.Test; 23 import org.junit.Test;
25 -
26 import org.junit.rules.ExpectedException; 24 import org.junit.rules.ExpectedException;
27 -import org.onosproject.yangutils.datamodel.YangNode; 25 +import org.onosproject.yangutils.datamodel.YangDataTypes;
28 -import org.onosproject.yangutils.datamodel.YangModule;
29 -import org.onosproject.yangutils.datamodel.YangNodeType;
30 import org.onosproject.yangutils.datamodel.YangLeaf; 26 import org.onosproject.yangutils.datamodel.YangLeaf;
31 import org.onosproject.yangutils.datamodel.YangLeafList; 27 import org.onosproject.yangutils.datamodel.YangLeafList;
32 -import org.onosproject.yangutils.datamodel.YangDataTypes; 28 +import org.onosproject.yangutils.datamodel.YangModule;
33 -import org.onosproject.yangutils.datamodel.YangStringRestriction; 29 +import org.onosproject.yangutils.datamodel.YangNode;
30 +import org.onosproject.yangutils.datamodel.YangNodeType;
34 import org.onosproject.yangutils.datamodel.YangRangeInterval; 31 import org.onosproject.yangutils.datamodel.YangRangeInterval;
35 import org.onosproject.yangutils.datamodel.YangRangeRestriction; 32 import org.onosproject.yangutils.datamodel.YangRangeRestriction;
33 +import org.onosproject.yangutils.datamodel.YangStringRestriction;
36 import org.onosproject.yangutils.datamodel.YangTypeDef; 34 import org.onosproject.yangutils.datamodel.YangTypeDef;
37 import org.onosproject.yangutils.parser.exceptions.ParserException; 35 import org.onosproject.yangutils.parser.exceptions.ParserException;
38 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 36 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
...@@ -71,11 +69,11 @@ public class LengthRestrictionListenerTest { ...@@ -71,11 +69,11 @@ public class LengthRestrictionListenerTest {
71 assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); 69 assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
72 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); 70 assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
73 YangStringRestriction stringRestriction = (YangStringRestriction) leafInfo 71 YangStringRestriction stringRestriction = (YangStringRestriction) leafInfo
74 - .getDataType().getDataTypeExtendedInfo(); 72 + .getDataType().getDataTypeExtendedInfo();
75 YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction(); 73 YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction();
76 74
77 ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals() 75 ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
78 - .listIterator(); 76 + .listIterator();
79 77
80 YangRangeInterval rangeInterval = lengthListIterator.next(); 78 YangRangeInterval rangeInterval = lengthListIterator.next();
81 79
...@@ -220,7 +218,7 @@ public class LengthRestrictionListenerTest { ...@@ -220,7 +218,7 @@ public class LengthRestrictionListenerTest {
220 @Test 218 @Test
221 public void processLengthWithInvalidIntegerPattern() throws IOException, ParserException { 219 public void processLengthWithInvalidIntegerPattern() throws IOException, ParserException {
222 thrown.expect(ParserException.class); 220 thrown.expect(ParserException.class);
223 - thrown.expectMessage("YANG file error : a is not valid."); 221 + thrown.expectMessage("YANG file error : Input value \"a\" is not a valid uint64.");
224 YangNode node = manager.getDataModel("src/test/resources/LengthWithInvalidIntegerPattern.yang"); 222 YangNode node = manager.getDataModel("src/test/resources/LengthWithInvalidIntegerPattern.yang");
225 } 223 }
226 224
......
...@@ -18,18 +18,17 @@ package org.onosproject.yangutils.parser.impl.listeners; ...@@ -18,18 +18,17 @@ package org.onosproject.yangutils.parser.impl.listeners;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.util.ListIterator; 20 import java.util.ListIterator;
21 -
22 import org.junit.Rule; 21 import org.junit.Rule;
23 import org.junit.Test; 22 import org.junit.Test;
24 import org.junit.rules.ExpectedException; 23 import org.junit.rules.ExpectedException;
25 -import org.onosproject.yangutils.datamodel.YangNode; 24 +import org.onosproject.yangutils.datamodel.YangDataTypes;
26 import org.onosproject.yangutils.datamodel.YangLeaf; 25 import org.onosproject.yangutils.datamodel.YangLeaf;
27 import org.onosproject.yangutils.datamodel.YangLeafList; 26 import org.onosproject.yangutils.datamodel.YangLeafList;
28 -import org.onosproject.yangutils.datamodel.YangRangeRestriction;
29 -import org.onosproject.yangutils.datamodel.YangRangeInterval;
30 import org.onosproject.yangutils.datamodel.YangModule; 27 import org.onosproject.yangutils.datamodel.YangModule;
28 +import org.onosproject.yangutils.datamodel.YangNode;
31 import org.onosproject.yangutils.datamodel.YangNodeType; 29 import org.onosproject.yangutils.datamodel.YangNodeType;
32 -import org.onosproject.yangutils.datamodel.YangDataTypes; 30 +import org.onosproject.yangutils.datamodel.YangRangeInterval;
31 +import org.onosproject.yangutils.datamodel.YangRangeRestriction;
33 import org.onosproject.yangutils.parser.exceptions.ParserException; 32 import org.onosproject.yangutils.parser.exceptions.ParserException;
34 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; 33 import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
35 import org.onosproject.yangutils.utils.builtindatatype.YangInt32; 34 import org.onosproject.yangutils.utils.builtindatatype.YangInt32;
...@@ -70,7 +69,7 @@ public class RangeRestrictionListenerTest { ...@@ -70,7 +69,7 @@ public class RangeRestrictionListenerTest {
70 .getDataType().getDataTypeExtendedInfo(); 69 .getDataType().getDataTypeExtendedInfo();
71 70
72 ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals() 71 ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
73 - .listIterator(); 72 + .listIterator();
74 YangRangeInterval rangeInterval = rangeListIterator.next(); 73 YangRangeInterval rangeInterval = rangeListIterator.next();
75 assertThat(((YangInt32) rangeInterval.getStartValue()).getValue(), is(1)); 74 assertThat(((YangInt32) rangeInterval.getStartValue()).getValue(), is(1));
76 assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4)); 75 assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4));
...@@ -172,7 +171,7 @@ public class RangeRestrictionListenerTest { ...@@ -172,7 +171,7 @@ public class RangeRestrictionListenerTest {
172 @Test 171 @Test
173 public void processRangeWithInvalidIntegerPattern() throws IOException, ParserException { 172 public void processRangeWithInvalidIntegerPattern() throws IOException, ParserException {
174 thrown.expect(ParserException.class); 173 thrown.expect(ParserException.class);
175 - thrown.expectMessage("YANG file error : a is not valid."); 174 + thrown.expectMessage("YANG file error : Input value \"a\" is not a valid int32.");
176 YangNode node = manager.getDataModel("src/test/resources/RangeWithInvalidIntegerPattern.yang"); 175 YangNode node = manager.getDataModel("src/test/resources/RangeWithInvalidIntegerPattern.yang");
177 } 176 }
178 } 177 }
......
...@@ -10,7 +10,7 @@ module Test { ...@@ -10,7 +10,7 @@ module Test {
10 } 10 }
11 } 11 }
12 typedef hello { 12 typedef hello {
13 - type String; 13 + type string;
14 } 14 }
15 } 15 }
16 } 16 }
......
...@@ -11,6 +11,6 @@ module Test { ...@@ -11,6 +11,6 @@ module Test {
11 } 11 }
12 } 12 }
13 typedef hello { 13 typedef hello {
14 - type String; 14 + type string;
15 } 15 }
16 } 16 }
......
...@@ -3,7 +3,7 @@ module Test { ...@@ -3,7 +3,7 @@ module Test {
3 namespace http://huawei.com; 3 namespace http://huawei.com;
4 prefix Ant; 4 prefix Ant;
5 typedef hello { 5 typedef hello {
6 - type String; 6 + type string;
7 } 7 }
8 container ospf { 8 container ospf {
9 list valid { 9 list valid {
......
...@@ -7,14 +7,14 @@ module Test { ...@@ -7,14 +7,14 @@ module Test {
7 } 7 }
8 grouping Percentage { 8 grouping Percentage {
9 leaf hello{ 9 leaf hello{
10 - type String; 10 + type string;
11 } 11 }
12 } 12 }
13 container ospf { 13 container ospf {
14 list valid { 14 list valid {
15 key "invalid"; 15 key "invalid";
16 - leaf invalid{ 16 + leaf invalid{
17 - type String; 17 + type string;
18 } 18 }
19 uses Ant:FirstClass; 19 uses Ant:FirstClass;
20 grouping FirstClass { 20 grouping FirstClass {
......
...@@ -3,15 +3,15 @@ module Test { ...@@ -3,15 +3,15 @@ module Test {
3 namespace http://huawei.com; 3 namespace http://huawei.com;
4 prefix Ant; 4 prefix Ant;
5 grouping Percentage { 5 grouping Percentage {
6 - leaf hello{ 6 + leaf hello{
7 - type String; 7 + type string;
8 } 8 }
9 } 9 }
10 container ospf { 10 container ospf {
11 list valid { 11 list valid {
12 key "invalid"; 12 key "invalid";
13 - leaf invalid{ 13 + leaf invalid{
14 - type String; 14 + type string;
15 } 15 }
16 uses Ant:FirstClass; 16 uses Ant:FirstClass;
17 grouping FirstClass { 17 grouping FirstClass {
......
...@@ -6,6 +6,6 @@ module Test { ...@@ -6,6 +6,6 @@ module Test {
6 type hello; 6 type hello;
7 } 7 }
8 typedef hello { 8 typedef hello {
9 - type String; 9 + type string;
10 } 10 }
11 } 11 }
......
...@@ -4,8 +4,8 @@ module Test { ...@@ -4,8 +4,8 @@ module Test {
4 prefix Ant; 4 prefix Ant;
5 uses hello; 5 uses hello;
6 grouping hello { 6 grouping hello {
7 - leaf hello{ 7 + leaf hello{
8 - type String; 8 + type string;
9 } 9 }
10 } 10 }
11 } 11 }
......
...@@ -4,12 +4,12 @@ module Test { ...@@ -4,12 +4,12 @@ module Test {
4 prefix Ant; 4 prefix Ant;
5 uses treat; 5 uses treat;
6 grouping treat { 6 grouping treat {
7 - leaf treat{ 7 + leaf treat{
8 - type String; 8 + type string;
9 } 9 }
10 container test{ 10 container test{
11 leaf leaf2{ 11 leaf leaf2{
12 - type String; 12 + type string;
13 } 13 }
14 } 14 }
15 } 15 }
......