Committed by
Gerrit Code Review
YANG uses and UT
Change-Id: Id3ec5cfed2b8e2a7d2d580786c70b5804f03ecfa
Showing
30 changed files
with
483 additions
and
113 deletions
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.yangutils.datamodel; | 16 | package org.onosproject.yangutils.datamodel; |
17 | 17 | ||
18 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 18 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
19 | +import org.onosproject.yangutils.parser.Parsable; | ||
19 | import org.onosproject.yangutils.translator.tojava.TraversalType; | 20 | import org.onosproject.yangutils.translator.tojava.TraversalType; |
20 | 21 | ||
21 | import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD; | 22 | import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD; |
... | @@ -281,9 +282,11 @@ public abstract class YangNode | ... | @@ -281,9 +282,11 @@ public abstract class YangNode |
281 | if (nextNodeToClone == null) { | 282 | if (nextNodeToClone == null) { |
282 | throw new DataModelException("Internal error: Cloning failed, source tree null pointer reached"); | 283 | throw new DataModelException("Internal error: Cloning failed, source tree null pointer reached"); |
283 | } | 284 | } |
284 | - | 285 | + if (curTraversal != PARENT) { |
285 | - if (curTraversal == CHILD) { | ||
286 | newNode = nextNodeToClone.clone(); | 286 | newNode = nextNodeToClone.clone(); |
287 | + detectCollisionWhileCloning(clonedTreeCurNode, newNode, curTraversal); | ||
288 | + } | ||
289 | + if (curTraversal == CHILD) { | ||
287 | 290 | ||
288 | /** | 291 | /** |
289 | * add the new node to the cloned tree. | 292 | * add the new node to the cloned tree. |
... | @@ -295,7 +298,6 @@ public abstract class YangNode | ... | @@ -295,7 +298,6 @@ public abstract class YangNode |
295 | */ | 298 | */ |
296 | clonedTreeCurNode = newNode; | 299 | clonedTreeCurNode = newNode; |
297 | } else if (curTraversal == SIBILING) { | 300 | } else if (curTraversal == SIBILING) { |
298 | - newNode = nextNodeToClone.clone(); | ||
299 | 301 | ||
300 | clonedTreeCurNode.addNextSibling(newNode); | 302 | clonedTreeCurNode.addNextSibling(newNode); |
301 | clonedTreeCurNode = newNode; | 303 | clonedTreeCurNode = newNode; |
... | @@ -328,6 +330,38 @@ public abstract class YangNode | ... | @@ -328,6 +330,38 @@ public abstract class YangNode |
328 | } | 330 | } |
329 | 331 | ||
330 | /** | 332 | /** |
333 | + * Detects collision when the grouping is deep copied to the uses's parent. | ||
334 | + * | ||
335 | + * @param currentNode parent/previous sibling node for the new node | ||
336 | + * @param newNode node which has to be added | ||
337 | + * @param addAs traversal type of the node | ||
338 | + * @throws DataModelException data model error | ||
339 | + */ | ||
340 | + private static void detectCollisionWhileCloning(YangNode currentNode, YangNode newNode, TraversalType addAs) | ||
341 | + throws DataModelException { | ||
342 | + if ((!(currentNode instanceof CollisionDetector)) | ||
343 | + || (!(newNode instanceof Parsable))) { | ||
344 | + throw new DataModelException("Node in data model tree does not support collision detection"); | ||
345 | + } | ||
346 | + | ||
347 | + CollisionDetector collisionDetector = (CollisionDetector) currentNode; | ||
348 | + Parsable parsable = (Parsable) newNode; | ||
349 | + if (addAs == TraversalType.CHILD) { | ||
350 | + collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType()); | ||
351 | + } else if (addAs == TraversalType.SIBILING) { | ||
352 | + currentNode = currentNode.getParent(); | ||
353 | + if (!(currentNode instanceof CollisionDetector)) { | ||
354 | + throw new DataModelException("Node in data model tree does not support collision detection"); | ||
355 | + } | ||
356 | + collisionDetector = (CollisionDetector) currentNode; | ||
357 | + collisionDetector.detectCollidingChild(newNode.getName(), parsable.getYangConstructType()); | ||
358 | + } else { | ||
359 | + throw new DataModelException("Errored tree cloning"); | ||
360 | + } | ||
361 | + | ||
362 | + } | ||
363 | + | ||
364 | + /** | ||
331 | * Add a new next sibling. | 365 | * Add a new next sibling. |
332 | * | 366 | * |
333 | * @param newSibling new sibling to be added | 367 | * @param newSibling new sibling to be added | ... | ... |
... | @@ -19,6 +19,7 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ... | @@ -19,6 +19,7 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
19 | import org.onosproject.yangutils.parser.Parsable; | 19 | import org.onosproject.yangutils.parser.Parsable; |
20 | import org.onosproject.yangutils.utils.YangConstructType; | 20 | import org.onosproject.yangutils.utils.YangConstructType; |
21 | 21 | ||
22 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil; | ||
22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; | 23 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; |
23 | 24 | ||
24 | /*- | 25 | /*- |
... | @@ -56,7 +57,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy | ... | @@ -56,7 +57,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy |
56 | */ | 57 | */ |
57 | public class YangUses | 58 | public class YangUses |
58 | extends YangNode | 59 | extends YangNode |
59 | - implements YangCommonInfo, Parsable, Resolvable { | 60 | + implements YangCommonInfo, Parsable, Resolvable, CollisionDetector { |
60 | 61 | ||
61 | /** | 62 | /** |
62 | * YANG node identifier. | 63 | * YANG node identifier. |
... | @@ -267,18 +268,23 @@ public class YangUses | ... | @@ -267,18 +268,23 @@ public class YangUses |
267 | } | 268 | } |
268 | 269 | ||
269 | YangNode usesParentNode = getParentNodeInGenCode(this); | 270 | YangNode usesParentNode = getParentNodeInGenCode(this); |
270 | - if (!(usesParentNode instanceof YangLeavesHolder)) { | 271 | + if ((!(usesParentNode instanceof YangLeavesHolder)) |
272 | + || (!(usesParentNode instanceof CollisionDetector))) { | ||
271 | throw new DataModelException("YANG uses holder construct is wrong"); | 273 | throw new DataModelException("YANG uses holder construct is wrong"); |
272 | } | 274 | } |
273 | 275 | ||
274 | YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode; | 276 | YangLeavesHolder usesParentLeavesHolder = (YangLeavesHolder) usesParentNode; |
275 | if (referredGrouping.getListOfLeaf() != null) { | 277 | if (referredGrouping.getListOfLeaf() != null) { |
276 | for (YangLeaf leaf : referredGrouping.getListOfLeaf()) { | 278 | for (YangLeaf leaf : referredGrouping.getListOfLeaf()) { |
279 | + ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leaf.getLeafName(), | ||
280 | + YangConstructType.LEAF_DATA); | ||
277 | usesParentLeavesHolder.addLeaf(leaf); | 281 | usesParentLeavesHolder.addLeaf(leaf); |
278 | } | 282 | } |
279 | } | 283 | } |
280 | if (referredGrouping.getListOfLeafList() != null) { | 284 | if (referredGrouping.getListOfLeafList() != null) { |
281 | for (YangLeafList leafList : referredGrouping.getListOfLeafList()) { | 285 | for (YangLeafList leafList : referredGrouping.getListOfLeafList()) { |
286 | + ((CollisionDetector) usesParentLeavesHolder).detectCollidingChild(leafList.getLeafName(), | ||
287 | + YangConstructType.LEAF_LIST_DATA); | ||
282 | usesParentLeavesHolder.addLeafList(leafList); | 288 | usesParentLeavesHolder.addLeafList(leafList); |
283 | } | 289 | } |
284 | } | 290 | } |
... | @@ -295,4 +301,19 @@ public class YangUses | ... | @@ -295,4 +301,19 @@ public class YangUses |
295 | public void setResolvableStatus(ResolvableStatus resolvableStatus) { | 301 | public void setResolvableStatus(ResolvableStatus resolvableStatus) { |
296 | this.resolvableStatus = resolvableStatus; | 302 | this.resolvableStatus = resolvableStatus; |
297 | } | 303 | } |
304 | + | ||
305 | + @Override | ||
306 | + public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { | ||
307 | + detectCollidingChildUtil(identifierName, dataType, this); | ||
308 | + } | ||
309 | + | ||
310 | + @Override | ||
311 | + public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { | ||
312 | + | ||
313 | + if (getName().equals(identifierName)) { | ||
314 | + throw new DataModelException("YANG file error: Duplicate input identifier detected, same as uses \"" | ||
315 | + + getName() + "\""); | ||
316 | + } | ||
317 | + } | ||
318 | + | ||
298 | } | 319 | } | ... | ... |
... | @@ -27,9 +27,9 @@ import org.onosproject.yangutils.datamodel.YangLeavesHolder; | ... | @@ -27,9 +27,9 @@ import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
27 | import org.onosproject.yangutils.datamodel.YangNode; | 27 | import org.onosproject.yangutils.datamodel.YangNode; |
28 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; | 28 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; |
29 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 29 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
30 | +import org.onosproject.yangutils.parser.Parsable; | ||
30 | import org.onosproject.yangutils.utils.YangConstructType; | 31 | import org.onosproject.yangutils.utils.YangConstructType; |
31 | 32 | ||
32 | - | ||
33 | /** | 33 | /** |
34 | * Represents utilities for data model tree. | 34 | * Represents utilities for data model tree. |
35 | */ | 35 | */ |
... | @@ -53,21 +53,44 @@ public final class DataModelUtils { | ... | @@ -53,21 +53,44 @@ public final class DataModelUtils { |
53 | public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node) | 53 | public static void detectCollidingChildUtil(String identifierName, YangConstructType dataType, YangNode node) |
54 | throws DataModelException { | 54 | throws DataModelException { |
55 | 55 | ||
56 | - if (dataType == YangConstructType.LEAF_DATA) { | 56 | + if (dataType == YangConstructType.USES_DATA || dataType == YangConstructType.GROUPING_DATA) { |
57 | + detectCollidingForUsesGrouping(identifierName, dataType, node); | ||
58 | + } else { | ||
59 | + if (node instanceof YangLeavesHolder) { | ||
57 | YangLeavesHolder leavesHolder = (YangLeavesHolder) node; | 60 | YangLeavesHolder leavesHolder = (YangLeavesHolder) node; |
58 | - if (leavesHolder.getListOfLeaf() != null) { | 61 | + detectCollidingLeaf(leavesHolder.getListOfLeaf(), identifierName); |
59 | - detectCollidingLeaf(leavesHolder, identifierName); | 62 | + detectCollidingLeafList(leavesHolder.getListOfLeafList(), identifierName); |
60 | } | 63 | } |
64 | + node = node.getChild(); | ||
65 | + while (node != null) { | ||
66 | + Parsable parsable = (Parsable) node; | ||
67 | + if (node instanceof CollisionDetector | ||
68 | + && (parsable.getYangConstructType() != YangConstructType.USES_DATA) | ||
69 | + && (parsable.getYangConstructType() != YangConstructType.GROUPING_DATA)) { | ||
70 | + ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); | ||
61 | } | 71 | } |
62 | - if (dataType == YangConstructType.LEAF_LIST_DATA) { | 72 | + node = node.getNextSibling(); |
63 | - if (((YangLeavesHolder) node).getListOfLeafList() != null) { | ||
64 | - YangLeavesHolder leavesHolder = (YangLeavesHolder) node; | ||
65 | - detectCollidingLeafList(leavesHolder, identifierName); | ||
66 | } | 73 | } |
67 | } | 74 | } |
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * Detects colliding of uses and grouping only with uses and grouping respectively. | ||
79 | + * | ||
80 | + * @param identifierName name for which collision detection is to be | ||
81 | + * checked | ||
82 | + * @param dataType type of YANG node asking for detecting collision | ||
83 | + * @param node node instance of calling node | ||
84 | + * @throws DataModelException a violation of data model rules | ||
85 | + */ | ||
86 | + public static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node) | ||
87 | + throws DataModelException { | ||
88 | + | ||
68 | node = node.getChild(); | 89 | node = node.getChild(); |
69 | while (node != null) { | 90 | while (node != null) { |
70 | - if (node instanceof CollisionDetector) { | 91 | + Parsable parsable = (Parsable) node; |
92 | + if (node instanceof CollisionDetector | ||
93 | + && (parsable.getYangConstructType() == dataType)) { | ||
71 | ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); | 94 | ((CollisionDetector) node).detectSelfCollision(identifierName, dataType); |
72 | } | 95 | } |
73 | node = node.getNextSibling(); | 96 | node = node.getNextSibling(); |
... | @@ -77,15 +100,18 @@ public final class DataModelUtils { | ... | @@ -77,15 +100,18 @@ public final class DataModelUtils { |
77 | /** | 100 | /** |
78 | * Detects the colliding identifier name in a given leaf node. | 101 | * Detects the colliding identifier name in a given leaf node. |
79 | * | 102 | * |
80 | - * @param leavesHolder leaves node against which collision to be checked | 103 | + * @param listOfLeaf List of leaves to detect collision |
81 | * @param identifierName name for which collision detection is to be | 104 | * @param identifierName name for which collision detection is to be |
82 | * checked | 105 | * checked |
83 | * @throws DataModelException a violation of data model rules | 106 | * @throws DataModelException a violation of data model rules |
84 | */ | 107 | */ |
85 | - private static void detectCollidingLeaf(YangLeavesHolder leavesHolder, String identifierName) | 108 | + private static void detectCollidingLeaf(List<YangLeaf> listOfLeaf, String identifierName) |
86 | throws DataModelException { | 109 | throws DataModelException { |
87 | 110 | ||
88 | - for (YangLeaf leaf : leavesHolder.getListOfLeaf()) { | 111 | + if (listOfLeaf == null) { |
112 | + return; | ||
113 | + } | ||
114 | + for (YangLeaf leaf : listOfLeaf) { | ||
89 | if (leaf.getLeafName().equals(identifierName)) { | 115 | if (leaf.getLeafName().equals(identifierName)) { |
90 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \"" | 116 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf \"" |
91 | + leaf.getLeafName() + "\""); | 117 | + leaf.getLeafName() + "\""); |
... | @@ -96,15 +122,18 @@ public final class DataModelUtils { | ... | @@ -96,15 +122,18 @@ public final class DataModelUtils { |
96 | /** | 122 | /** |
97 | * Detects the colliding identifier name in a given leaf-list node. | 123 | * Detects the colliding identifier name in a given leaf-list node. |
98 | * | 124 | * |
99 | - * @param leavesHolder leaves node against which collision to be checked | 125 | + * @param listOfLeafList list of leaf-lists to detect collision |
100 | * @param identifierName name for which collision detection is to be | 126 | * @param identifierName name for which collision detection is to be |
101 | * checked | 127 | * checked |
102 | * @throws DataModelException a violation of data model rules | 128 | * @throws DataModelException a violation of data model rules |
103 | */ | 129 | */ |
104 | - private static void detectCollidingLeafList(YangLeavesHolder leavesHolder, String identifierName) | 130 | + private static void detectCollidingLeafList(List<YangLeafList> listOfLeafList, String identifierName) |
105 | throws DataModelException { | 131 | throws DataModelException { |
106 | 132 | ||
107 | - for (YangLeafList leafList : leavesHolder.getListOfLeafList()) { | 133 | + if (listOfLeafList == null) { |
134 | + return; | ||
135 | + } | ||
136 | + for (YangLeafList leafList : listOfLeafList) { | ||
108 | if (leafList.getLeafName().equals(identifierName)) { | 137 | if (leafList.getLeafName().equals(identifierName)) { |
109 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " + | 138 | throw new DataModelException("YANG file error: Duplicate input identifier detected, same as leaf " + |
110 | "list \"" + leafList.getLeafName() + "\""); | 139 | "list \"" + leafList.getLeafName() + "\""); |
... | @@ -122,8 +151,6 @@ public final class DataModelUtils { | ... | @@ -122,8 +151,6 @@ public final class DataModelUtils { |
122 | public static void addResolutionInfo(YangResolutionInfo resolutionInfo) | 151 | public static void addResolutionInfo(YangResolutionInfo resolutionInfo) |
123 | throws DataModelException { | 152 | throws DataModelException { |
124 | 153 | ||
125 | - | ||
126 | - | ||
127 | /* get the module node to add maintain the list of nested reference */ | 154 | /* get the module node to add maintain the list of nested reference */ |
128 | YangNode curNode = resolutionInfo.getEntityToResolveInfo() | 155 | YangNode curNode = resolutionInfo.getEntityToResolveInfo() |
129 | .getHolderOfEntityToResolve(); | 156 | .getHolderOfEntityToResolve(); |
... | @@ -142,6 +169,13 @@ public final class DataModelUtils { | ... | @@ -142,6 +169,13 @@ public final class DataModelUtils { |
142 | resolutionNode.addToResolutionList(resolutionInfo); | 169 | resolutionNode.addToResolutionList(resolutionInfo); |
143 | } | 170 | } |
144 | 171 | ||
172 | + /** | ||
173 | + * Evaluates whether the prefix in uses/type is valid. | ||
174 | + * | ||
175 | + * @param entityPrefix prefix in the current module/sub-module | ||
176 | + * @param resolutionNode uses/type node which has the prefix with it | ||
177 | + * @return whether prefix is valid or not | ||
178 | + */ | ||
145 | private static boolean isPrefixValid(String entityPrefix, HasResolutionInfo resolutionNode) { | 179 | private static boolean isPrefixValid(String entityPrefix, HasResolutionInfo resolutionNode) { |
146 | if (entityPrefix == null) { | 180 | if (entityPrefix == null) { |
147 | return true; | 181 | return true; | ... | ... |
... | @@ -1565,22 +1565,6 @@ public interface GeneratedYangListener extends ParseTreeListener { | ... | @@ -1565,22 +1565,6 @@ public interface GeneratedYangListener extends ParseTreeListener { |
1565 | 1565 | ||
1566 | /** | 1566 | /** |
1567 | * Enter a parse tree produced by GeneratedYangParser for grammar rule | 1567 | * Enter a parse tree produced by GeneratedYangParser for grammar rule |
1568 | - * inputStatementBody. | ||
1569 | - * | ||
1570 | - * @param currentContext current context in the parsed tree | ||
1571 | - */ | ||
1572 | - void enterInputStatementBody(GeneratedYangParser.InputStatementBodyContext currentContext); | ||
1573 | - | ||
1574 | - /** | ||
1575 | - * Exit a parse tree produced by GeneratedYangParser for grammar rule | ||
1576 | - * inputStatementBody. | ||
1577 | - * | ||
1578 | - * @param currentContext current context in the parsed tree | ||
1579 | - */ | ||
1580 | - void exitInputStatementBody(GeneratedYangParser.InputStatementBodyContext currentContext); | ||
1581 | - | ||
1582 | - /** | ||
1583 | - * Enter a parse tree produced by GeneratedYangParser for grammar rule | ||
1584 | * outputStatement. | 1568 | * outputStatement. |
1585 | * | 1569 | * |
1586 | * @param currentContext current context in the parsed tree | 1570 | * @param currentContext current context in the parsed tree |
... | @@ -1597,22 +1581,6 @@ public interface GeneratedYangListener extends ParseTreeListener { | ... | @@ -1597,22 +1581,6 @@ public interface GeneratedYangListener extends ParseTreeListener { |
1597 | 1581 | ||
1598 | /** | 1582 | /** |
1599 | * Enter a parse tree produced by GeneratedYangParser for grammar rule | 1583 | * Enter a parse tree produced by GeneratedYangParser for grammar rule |
1600 | - * outputStatementBody. | ||
1601 | - * | ||
1602 | - * @param currentContext current context in the parsed tree | ||
1603 | - */ | ||
1604 | - void enterOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext currentContext); | ||
1605 | - | ||
1606 | - /** | ||
1607 | - * Exit a parse tree produced by GeneratedYangParser for grammar rule | ||
1608 | - * outputStatementBody. | ||
1609 | - * | ||
1610 | - * @param currentContext current context in the parsed tree | ||
1611 | - */ | ||
1612 | - void exitOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext currentContext); | ||
1613 | - | ||
1614 | - /** | ||
1615 | - * Enter a parse tree produced by GeneratedYangParser for grammar rule | ||
1616 | * notificationStatement. | 1584 | * notificationStatement. |
1617 | * | 1585 | * |
1618 | * @param currentContext current context in the parsed tree | 1586 | * @param currentContext current context in the parsed tree | ... | ... |
... | @@ -52,8 +52,8 @@ import org.onosproject.yangutils.parser.impl.listeners.MandatoryListener; | ... | @@ -52,8 +52,8 @@ import org.onosproject.yangutils.parser.impl.listeners.MandatoryListener; |
52 | import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener; | 52 | import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener; |
53 | import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener; | 53 | import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener; |
54 | import org.onosproject.yangutils.parser.impl.listeners.ModuleListener; | 54 | import org.onosproject.yangutils.parser.impl.listeners.ModuleListener; |
55 | -import org.onosproject.yangutils.parser.impl.listeners.NotificationListener; | ||
56 | import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener; | 55 | import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener; |
56 | +import org.onosproject.yangutils.parser.impl.listeners.NotificationListener; | ||
57 | import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener; | 57 | import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener; |
58 | import org.onosproject.yangutils.parser.impl.listeners.OutputListener; | 58 | import org.onosproject.yangutils.parser.impl.listeners.OutputListener; |
59 | import org.onosproject.yangutils.parser.impl.listeners.PatternRestrictionListener; | 59 | import org.onosproject.yangutils.parser.impl.listeners.PatternRestrictionListener; |
... | @@ -1087,14 +1087,6 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -1087,14 +1087,6 @@ public class TreeWalkListener implements GeneratedYangListener { |
1087 | } | 1087 | } |
1088 | 1088 | ||
1089 | @Override | 1089 | @Override |
1090 | - public void enterInputStatementBody(GeneratedYangParser.InputStatementBodyContext ctx) { | ||
1091 | - } | ||
1092 | - | ||
1093 | - @Override | ||
1094 | - public void exitInputStatementBody(GeneratedYangParser.InputStatementBodyContext ctx) { | ||
1095 | - } | ||
1096 | - | ||
1097 | - @Override | ||
1098 | public void enterOutputStatement(GeneratedYangParser.OutputStatementContext ctx) { | 1090 | public void enterOutputStatement(GeneratedYangParser.OutputStatementContext ctx) { |
1099 | OutputListener.processOutputEntry(this, ctx); | 1091 | OutputListener.processOutputEntry(this, ctx); |
1100 | } | 1092 | } |
... | @@ -1105,14 +1097,6 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -1105,14 +1097,6 @@ public class TreeWalkListener implements GeneratedYangListener { |
1105 | } | 1097 | } |
1106 | 1098 | ||
1107 | @Override | 1099 | @Override |
1108 | - public void enterOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext ctx) { | ||
1109 | - } | ||
1110 | - | ||
1111 | - @Override | ||
1112 | - public void exitOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext ctx) { | ||
1113 | - } | ||
1114 | - | ||
1115 | - @Override | ||
1116 | public void enterNotificationStatement(GeneratedYangParser.NotificationStatementContext ctx) { | 1100 | public void enterNotificationStatement(GeneratedYangParser.NotificationStatementContext ctx) { |
1117 | NotificationListener.processNotificationEntry(this, ctx); | 1101 | NotificationListener.processNotificationEntry(this, ctx); |
1118 | } | 1102 | } | ... | ... |
... | @@ -46,12 +46,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -46,12 +46,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
48 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 48 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
49 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
50 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; | 49 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; |
51 | import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA; | 50 | import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA; |
52 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; | 51 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; |
53 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | 52 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; |
54 | -import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA; | ||
55 | 53 | ||
56 | /* | 54 | /* |
57 | * Reference: RFC6020 and YANG ANTLR Grammar | 55 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -168,7 +166,5 @@ public final class GroupingListener { | ... | @@ -168,7 +166,5 @@ public final class GroupingListener { |
168 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, GROUPING_DATA, | 166 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, GROUPING_DATA, |
169 | ctx.identifier().getText()); | 167 | ctx.identifier().getText()); |
170 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, GROUPING_DATA, ctx.identifier().getText()); | 168 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, GROUPING_DATA, ctx.identifier().getText()); |
171 | - validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA, | ||
172 | - GROUPING_DATA, ctx.identifier().getText()); | ||
173 | } | 169 | } |
174 | } | 170 | } | ... | ... |
... | @@ -36,6 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -36,6 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; |
38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
39 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonZero; | ||
40 | +import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA; | ||
39 | import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA; | 41 | import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA; |
40 | 42 | ||
41 | /* | 43 | /* |
... | @@ -86,6 +88,9 @@ public final class InputListener { | ... | @@ -86,6 +88,9 @@ public final class InputListener { |
86 | // Check for stack to be non empty. | 88 | // Check for stack to be non empty. |
87 | checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", ENTRY); | 89 | checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", ENTRY); |
88 | 90 | ||
91 | + validateCardinalityNonZero(ctx.dataDefStatement(), DATA_DEF_DATA, | ||
92 | + INPUT_DATA, "", ctx); | ||
93 | + | ||
89 | Parsable curData = listener.getParsedDataStack().peek(); | 94 | Parsable curData = listener.getParsedDataStack().peek(); |
90 | if (curData instanceof YangRpc) { | 95 | if (curData instanceof YangRpc) { |
91 | 96 | ... | ... |
... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.parser.impl.listeners; | ... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.parser.impl.listeners; |
19 | import org.onosproject.yangutils.datamodel.YangAugment; | 19 | import org.onosproject.yangutils.datamodel.YangAugment; |
20 | import org.onosproject.yangutils.datamodel.YangCase; | 20 | import org.onosproject.yangutils.datamodel.YangCase; |
21 | import org.onosproject.yangutils.datamodel.YangContainer; | 21 | import org.onosproject.yangutils.datamodel.YangContainer; |
22 | +import org.onosproject.yangutils.datamodel.YangGrouping; | ||
22 | import org.onosproject.yangutils.datamodel.YangInput; | 23 | import org.onosproject.yangutils.datamodel.YangInput; |
23 | import org.onosproject.yangutils.datamodel.YangList; | 24 | import org.onosproject.yangutils.datamodel.YangList; |
24 | import org.onosproject.yangutils.datamodel.YangModule; | 25 | import org.onosproject.yangutils.datamodel.YangModule; |
... | @@ -140,7 +141,7 @@ public final class ListListener { | ... | @@ -140,7 +141,7 @@ public final class ListListener { |
140 | if (curData instanceof YangModule || curData instanceof YangContainer | 141 | if (curData instanceof YangModule || curData instanceof YangContainer |
141 | || curData instanceof YangList || curData instanceof YangCase | 142 | || curData instanceof YangList || curData instanceof YangCase |
142 | || curData instanceof YangNotification || curData instanceof YangInput | 143 | || curData instanceof YangNotification || curData instanceof YangInput |
143 | - || curData instanceof YangOutput || curData instanceof YangAugment) { | 144 | + || curData instanceof YangOutput || curData instanceof YangAugment || curData instanceof YangGrouping) { |
144 | curNode = (YangNode) curData; | 145 | curNode = (YangNode) curData; |
145 | try { | 146 | try { |
146 | curNode.addChild(yangList); | 147 | curNode.addChild(yangList); | ... | ... |
... | @@ -40,13 +40,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -40,13 +40,10 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
43 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
44 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; | 43 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; |
45 | -import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA; | ||
46 | import static org.onosproject.yangutils.utils.YangConstructType.NOTIFICATION_DATA; | 44 | import static org.onosproject.yangutils.utils.YangConstructType.NOTIFICATION_DATA; |
47 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; | 45 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; |
48 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | 46 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; |
49 | -import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA; | ||
50 | 47 | ||
51 | /* | 48 | /* |
52 | * Reference: RFC6020 and YANG ANTLR Grammar | 49 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -159,7 +156,5 @@ public final class NotificationListener { | ... | @@ -159,7 +156,5 @@ public final class NotificationListener { |
159 | ctx.identifier().getText()); | 156 | ctx.identifier().getText()); |
160 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, NOTIFICATION_DATA, | 157 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, NOTIFICATION_DATA, |
161 | ctx.identifier().getText()); | 158 | ctx.identifier().getText()); |
162 | - validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA, | ||
163 | - NOTIFICATION_DATA, ctx.identifier().getText()); | ||
164 | } | 159 | } |
165 | } | 160 | } | ... | ... |
... | @@ -36,6 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -36,6 +36,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; |
38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
39 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonZero; | ||
40 | +import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA; | ||
39 | import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA; | 41 | import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA; |
40 | 42 | ||
41 | /* | 43 | /* |
... | @@ -86,6 +88,9 @@ public final class OutputListener { | ... | @@ -86,6 +88,9 @@ public final class OutputListener { |
86 | // Check for stack to be non empty. | 88 | // Check for stack to be non empty. |
87 | checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", ENTRY); | 89 | checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", ENTRY); |
88 | 90 | ||
91 | + validateCardinalityNonZero(ctx.dataDefStatement(), DATA_DEF_DATA, | ||
92 | + OUTPUT_DATA, "", ctx); | ||
93 | + | ||
89 | Parsable curData = listener.getParsedDataStack().peek(); | 94 | Parsable curData = listener.getParsedDataStack().peek(); |
90 | if (curData instanceof YangRpc) { | 95 | if (curData instanceof YangRpc) { |
91 | 96 | ... | ... |
... | @@ -37,12 +37,9 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -37,12 +37,9 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; |
38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
40 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | ||
41 | import static org.onosproject.yangutils.utils.YangConstructType.RPC_DATA; | 40 | import static org.onosproject.yangutils.utils.YangConstructType.RPC_DATA; |
42 | import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA; | 41 | import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA; |
43 | import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA; | 42 | import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA; |
44 | -import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA; | ||
45 | -import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA; | ||
46 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | 43 | import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; |
47 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; | 44 | import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; |
48 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; | 45 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; |
... | @@ -157,8 +154,6 @@ public final class RpcListener { | ... | @@ -157,8 +154,6 @@ public final class RpcListener { |
157 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, RPC_DATA, ctx.identifier().getText()); | 154 | validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, RPC_DATA, ctx.identifier().getText()); |
158 | validateCardinalityMaxOne(ctx.inputStatement(), INPUT_DATA, RPC_DATA, ctx.identifier().getText()); | 155 | validateCardinalityMaxOne(ctx.inputStatement(), INPUT_DATA, RPC_DATA, ctx.identifier().getText()); |
159 | validateCardinalityMaxOne(ctx.outputStatement(), OUTPUT_DATA, RPC_DATA, ctx.identifier().getText()); | 156 | validateCardinalityMaxOne(ctx.outputStatement(), OUTPUT_DATA, RPC_DATA, ctx.identifier().getText()); |
160 | - validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA, | ||
161 | - RPC_DATA, ctx.identifier().getText()); | ||
162 | } | 157 | } |
163 | 158 | ||
164 | } | 159 | } | ... | ... |
... | @@ -17,6 +17,7 @@ | ... | @@ -17,6 +17,7 @@ |
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | import org.onosproject.yangutils.datamodel.YangContainer; | 19 | import org.onosproject.yangutils.datamodel.YangContainer; |
20 | +import org.onosproject.yangutils.datamodel.YangGrouping; | ||
20 | import org.onosproject.yangutils.datamodel.YangInput; | 21 | import org.onosproject.yangutils.datamodel.YangInput; |
21 | import org.onosproject.yangutils.datamodel.YangList; | 22 | import org.onosproject.yangutils.datamodel.YangList; |
22 | import org.onosproject.yangutils.datamodel.YangModule; | 23 | import org.onosproject.yangutils.datamodel.YangModule; |
... | @@ -127,11 +128,8 @@ public final class TypeDefListener { | ... | @@ -127,11 +128,8 @@ public final class TypeDefListener { |
127 | 128 | ||
128 | if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangContainer | 129 | if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangContainer |
129 | || curData instanceof YangList || curData instanceof YangNotification || curData instanceof YangRpc | 130 | || curData instanceof YangList || curData instanceof YangNotification || curData instanceof YangRpc |
130 | - || curData instanceof YangInput || curData instanceof YangOutput) { | 131 | + || curData instanceof YangInput || curData instanceof YangOutput || curData instanceof YangGrouping) { |
131 | 132 | ||
132 | - /* | ||
133 | - * TODO YangGrouping. | ||
134 | - */ | ||
135 | YangNode curNode = (YangNode) curData; | 133 | YangNode curNode = (YangNode) curData; |
136 | try { | 134 | try { |
137 | curNode.addChild(typeDefNode); | 135 | curNode.addChild(typeDefNode); | ... | ... |
... | @@ -23,8 +23,10 @@ import org.onosproject.yangutils.datamodel.YangInput; | ... | @@ -23,8 +23,10 @@ import org.onosproject.yangutils.datamodel.YangInput; |
23 | import org.onosproject.yangutils.datamodel.YangList; | 23 | import org.onosproject.yangutils.datamodel.YangList; |
24 | import org.onosproject.yangutils.datamodel.YangModule; | 24 | import org.onosproject.yangutils.datamodel.YangModule; |
25 | import org.onosproject.yangutils.datamodel.YangNode; | 25 | import org.onosproject.yangutils.datamodel.YangNode; |
26 | +import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | ||
26 | import org.onosproject.yangutils.datamodel.YangNotification; | 27 | import org.onosproject.yangutils.datamodel.YangNotification; |
27 | import org.onosproject.yangutils.datamodel.YangOutput; | 28 | import org.onosproject.yangutils.datamodel.YangOutput; |
29 | +import org.onosproject.yangutils.datamodel.YangResolutionInfo; | ||
28 | import org.onosproject.yangutils.datamodel.YangSubModule; | 30 | import org.onosproject.yangutils.datamodel.YangSubModule; |
29 | import org.onosproject.yangutils.datamodel.YangUses; | 31 | import org.onosproject.yangutils.datamodel.YangUses; |
30 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 32 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
... | @@ -33,16 +35,18 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ... | @@ -33,16 +35,18 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
33 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 35 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
34 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 36 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
35 | 37 | ||
38 | +import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo; | ||
36 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | 39 | import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; |
37 | import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangUsesNode; | 40 | import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangUsesNode; |
41 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | ||
38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 43 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | 44 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; |
41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 45 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
43 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | ||
44 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
45 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | 48 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; |
49 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier; | ||
46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 50 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 51 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
48 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; | 52 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; |
... | @@ -116,6 +120,11 @@ public final class UsesListener { | ... | @@ -116,6 +120,11 @@ public final class UsesListener { |
116 | // Validate sub statement cardinality. | 120 | // Validate sub statement cardinality. |
117 | validateSubStatementsCardinality(ctx); | 121 | validateSubStatementsCardinality(ctx); |
118 | 122 | ||
123 | + // Check for identifier collision | ||
124 | + int line = ctx.getStart().getLine(); | ||
125 | + int charPositionInLine = ctx.getStart().getCharPositionInLine(); | ||
126 | + | ||
127 | + detectCollidingChildUtil(listener, line, charPositionInLine, ctx.string().getText(), USES_DATA); | ||
119 | Parsable curData = listener.getParsedDataStack().peek(); | 128 | Parsable curData = listener.getParsedDataStack().peek(); |
120 | 129 | ||
121 | if (curData instanceof YangModule || curData instanceof YangSubModule | 130 | if (curData instanceof YangModule || curData instanceof YangSubModule |
... | @@ -126,8 +135,8 @@ public final class UsesListener { | ... | @@ -126,8 +135,8 @@ public final class UsesListener { |
126 | || curData instanceof YangNotification) { | 135 | || curData instanceof YangNotification) { |
127 | 136 | ||
128 | YangUses usesNode = getYangUsesNode(JAVA_GENERATION); | 137 | YangUses usesNode = getYangUsesNode(JAVA_GENERATION); |
129 | - usesNode.setName(ctx.string().getText()); | 138 | + YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), USES_DATA, ctx); |
130 | - | 139 | + usesNode.setNodeIdentifier(nodeIdentifier); |
131 | YangNode curNode = (YangNode) curData; | 140 | YangNode curNode = (YangNode) curData; |
132 | 141 | ||
133 | try { | 142 | try { |
... | @@ -156,12 +165,29 @@ public final class UsesListener { | ... | @@ -156,12 +165,29 @@ public final class UsesListener { |
156 | // Check for stack to be non empty. | 165 | // Check for stack to be non empty. |
157 | checkStackIsNotEmpty(listener, MISSING_HOLDER, USES_DATA, ctx.string().getText(), EXIT); | 166 | checkStackIsNotEmpty(listener, MISSING_HOLDER, USES_DATA, ctx.string().getText(), EXIT); |
158 | 167 | ||
159 | - if (listener.getParsedDataStack().peek() instanceof YangUses) { | 168 | + Parsable parsableUses = listener.getParsedDataStack().pop(); |
160 | - listener.getParsedDataStack().pop(); | 169 | + if (!(parsableUses instanceof YangUses)) { |
161 | - } else { | 170 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, USES_DATA, |
162 | - throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, USES_DATA, | ||
163 | ctx.string().getText(), EXIT)); | 171 | ctx.string().getText(), EXIT)); |
164 | } | 172 | } |
173 | + YangUses uses = (YangUses) parsableUses; | ||
174 | + int errorLine = ctx.getStart().getLine(); | ||
175 | + int errorPosition = ctx.getStart().getCharPositionInLine(); | ||
176 | + | ||
177 | + // Parent YANG node of uses to be added in resolution information. | ||
178 | + Parsable parentNode = listener.getParsedDataStack().peek(); | ||
179 | + | ||
180 | + // Verify parent node of leaf | ||
181 | + if (!(parentNode instanceof YangNode)) { | ||
182 | + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, USES_DATA, | ||
183 | + ctx.string().getText(), EXIT)); | ||
184 | + } | ||
185 | + | ||
186 | + // Add resolution information to the list | ||
187 | + YangResolutionInfo resolutionInfo = new YangResolutionInfo<YangUses>(uses, | ||
188 | + (YangNode) parentNode, errorLine, | ||
189 | + errorPosition); | ||
190 | + addToResolutionList(resolutionInfo, ctx); | ||
165 | } | 191 | } |
166 | 192 | ||
167 | // TODO linker to handle collision scenarios like leaf obtained by uses, conflicts with some existing leaf. | 193 | // TODO linker to handle collision scenarios like leaf obtained by uses, conflicts with some existing leaf. |
... | @@ -175,5 +201,23 @@ public final class UsesListener { | ... | @@ -175,5 +201,23 @@ public final class UsesListener { |
175 | validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, USES_DATA, ctx.string().getText()); | 201 | validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, USES_DATA, ctx.string().getText()); |
176 | validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, USES_DATA, ctx.string().getText()); | 202 | validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, USES_DATA, ctx.string().getText()); |
177 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, USES_DATA, ctx.string().getText()); | 203 | validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, USES_DATA, ctx.string().getText()); |
178 | - validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, USES_DATA, ctx.string().getText()); } | 204 | + validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, USES_DATA, ctx.string().getText()); |
205 | + } | ||
206 | + | ||
207 | + /** | ||
208 | + * Add to resolution list. | ||
209 | + * | ||
210 | + * @param resolutionInfo resolution information. | ||
211 | + * @param ctx context object of the grammar rule | ||
212 | + */ | ||
213 | + private static void addToResolutionList(YangResolutionInfo<YangUses> resolutionInfo, | ||
214 | + GeneratedYangParser.UsesStatementContext ctx) { | ||
215 | + | ||
216 | + try { | ||
217 | + addResolutionInfo(resolutionInfo); | ||
218 | + } catch (DataModelException e) { | ||
219 | + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | ||
220 | + USES_DATA, ctx.string().getText(), EXIT, e.getMessage())); | ||
221 | + } | ||
222 | + } | ||
179 | } | 223 | } | ... | ... |
... | @@ -1098,12 +1098,7 @@ package org.onosproject.yangutils.parser.antlrgencode; | ... | @@ -1098,12 +1098,7 @@ package org.onosproject.yangutils.parser.antlrgencode; |
1098 | * 1*(data-def-stmt stmtsep) | 1098 | * 1*(data-def-stmt stmtsep) |
1099 | * "}" | 1099 | * "}" |
1100 | */ | 1100 | */ |
1101 | - inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE inputStatementBody RIGHT_CURLY_BRACE; | 1101 | + inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE (typedefStatement | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE; |
1102 | - | ||
1103 | - inputStatementBody : typedefStatement* dataDefStatement+ | ||
1104 | - | dataDefStatement+ typedefStatement* | ||
1105 | - | groupingStatement* dataDefStatement+ | ||
1106 | - | dataDefStatement+ groupingStatement*; | ||
1107 | 1102 | ||
1108 | /** | 1103 | /** |
1109 | * output-stmt = output-keyword optsep | 1104 | * output-stmt = output-keyword optsep |
... | @@ -1114,12 +1109,7 @@ package org.onosproject.yangutils.parser.antlrgencode; | ... | @@ -1114,12 +1109,7 @@ package org.onosproject.yangutils.parser.antlrgencode; |
1114 | * 1*(data-def-stmt stmtsep) | 1109 | * 1*(data-def-stmt stmtsep) |
1115 | * "}" | 1110 | * "}" |
1116 | */ | 1111 | */ |
1117 | - outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE outputStatementBody RIGHT_CURLY_BRACE; | 1112 | + outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE (typedefStatement | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE; |
1118 | - | ||
1119 | - outputStatementBody : typedefStatement* dataDefStatement+ | ||
1120 | - | dataDefStatement+ typedefStatement* | ||
1121 | - | groupingStatement* dataDefStatement+ | ||
1122 | - | dataDefStatement+ groupingStatement*; | ||
1123 | 1113 | ||
1124 | /** | 1114 | /** |
1125 | * notification-stmt = notification-keyword sep | 1115 | * notification-stmt = notification-keyword sep | ... | ... |
utils/yangutils/src/test/java/org/onosproject/yangutils/linker/IntraFileUsesLinkingTest.java
0 → 100644
This diff is collapsed. Click to expand it.
... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.parser.impl.listeners; | ... | @@ -19,6 +19,7 @@ package org.onosproject.yangutils.parser.impl.listeners; |
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | import org.junit.Test; | 20 | import org.junit.Test; |
21 | import org.onosproject.yangutils.datamodel.YangContainer; | 21 | import org.onosproject.yangutils.datamodel.YangContainer; |
22 | +import org.onosproject.yangutils.datamodel.YangGrouping; | ||
22 | import org.onosproject.yangutils.datamodel.YangList; | 23 | import org.onosproject.yangutils.datamodel.YangList; |
23 | import org.onosproject.yangutils.datamodel.YangModule; | 24 | import org.onosproject.yangutils.datamodel.YangModule; |
24 | import org.onosproject.yangutils.datamodel.YangNode; | 25 | import org.onosproject.yangutils.datamodel.YangNode; |
... | @@ -56,7 +57,10 @@ public class UsesListenerTest { | ... | @@ -56,7 +57,10 @@ public class UsesListenerTest { |
56 | YangModule yangNode = (YangModule) node; | 57 | YangModule yangNode = (YangModule) node; |
57 | assertThat(yangNode.getName(), is("Test")); | 58 | assertThat(yangNode.getName(), is("Test")); |
58 | 59 | ||
59 | - YangUses yangUses = (YangUses) yangNode.getChild(); | 60 | + YangGrouping yangGrouping = (YangGrouping) yangNode.getChild(); |
61 | + assertThat(yangGrouping.getName(), is("endpoint")); | ||
62 | + | ||
63 | + YangUses yangUses = (YangUses) yangGrouping.getNextSibling(); | ||
60 | assertThat(yangUses.getName(), is("endpoint")); | 64 | assertThat(yangUses.getName(), is("endpoint")); |
61 | } | 65 | } |
62 | 66 | ||
... | @@ -78,7 +82,10 @@ public class UsesListenerTest { | ... | @@ -78,7 +82,10 @@ public class UsesListenerTest { |
78 | YangModule yangNode = (YangModule) node; | 82 | YangModule yangNode = (YangModule) node; |
79 | assertThat(yangNode.getName(), is("Test")); | 83 | assertThat(yangNode.getName(), is("Test")); |
80 | 84 | ||
81 | - YangContainer yangContainer = (YangContainer) yangNode.getChild(); | 85 | + YangGrouping yangGrouping = (YangGrouping) yangNode.getChild(); |
86 | + assertThat(yangGrouping.getName(), is("endpoint")); | ||
87 | + | ||
88 | + YangContainer yangContainer = (YangContainer) yangGrouping.getNextSibling(); | ||
82 | assertThat(yangContainer.getName(), is("valid")); | 89 | assertThat(yangContainer.getName(), is("valid")); |
83 | 90 | ||
84 | YangUses yangUses = (YangUses) yangContainer.getChild(); | 91 | YangUses yangUses = (YangUses) yangContainer.getChild(); |
... | @@ -108,7 +115,10 @@ public class UsesListenerTest { | ... | @@ -108,7 +115,10 @@ public class UsesListenerTest { |
108 | YangModule yangNode = (YangModule) node; | 115 | YangModule yangNode = (YangModule) node; |
109 | assertThat(yangNode.getName(), is("Test")); | 116 | assertThat(yangNode.getName(), is("Test")); |
110 | 117 | ||
111 | - YangList yangList = (YangList) yangNode.getChild(); | 118 | + YangGrouping yangGrouping = (YangGrouping) yangNode.getChild(); |
119 | + assertThat(yangGrouping.getName(), is("endpoint")); | ||
120 | + | ||
121 | + YangList yangList = (YangList) yangGrouping.getNextSibling(); | ||
112 | assertThat(yangList.getName(), is("valid")); | 122 | assertThat(yangList.getName(), is("valid")); |
113 | 123 | ||
114 | YangUses yangUses = (YangUses) yangList.getChild(); | 124 | YangUses yangUses = (YangUses) yangList.getChild(); | ... | ... |
utils/yangutils/src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang
0 → 100644
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + import ietf-yang-types { | ||
6 | + prefix "P"; | ||
7 | + } | ||
8 | + grouping Percentage { | ||
9 | + leaf hello{ | ||
10 | + type String; | ||
11 | + } | ||
12 | + } | ||
13 | + container ospf { | ||
14 | + list valid { | ||
15 | + key "invalid"; | ||
16 | + leaf invalid{ | ||
17 | + type String; | ||
18 | + } | ||
19 | + uses Ant:FirstClass; | ||
20 | + grouping FirstClass { | ||
21 | + uses P:PassingClass; | ||
22 | + } | ||
23 | + } | ||
24 | + grouping PassingClass { | ||
25 | + uses Ant:Percentage; | ||
26 | + } | ||
27 | + } | ||
28 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + grouping Percentage { | ||
6 | + leaf hello{ | ||
7 | + type String; | ||
8 | + } | ||
9 | + } | ||
10 | + container ospf { | ||
11 | + list valid { | ||
12 | + key "invalid"; | ||
13 | + leaf invalid{ | ||
14 | + type String; | ||
15 | + } | ||
16 | + uses Ant:FirstClass; | ||
17 | + grouping FirstClass { | ||
18 | + uses PassingClass; | ||
19 | + } | ||
20 | + } | ||
21 | + grouping PassingClass { | ||
22 | + uses Ant:Percentage; | ||
23 | + } | ||
24 | + } | ||
25 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + container valid { | ||
6 | + grouping endpoint { | ||
7 | + leaf zip-code { | ||
8 | + type string; | ||
9 | + } | ||
10 | + uses failure; | ||
11 | + container hold { | ||
12 | + leaf newone { | ||
13 | + type string; | ||
14 | + } | ||
15 | + | ||
16 | + } | ||
17 | + uses failure; | ||
18 | + } | ||
19 | + grouping failure { | ||
20 | + leaf test { | ||
21 | + type string; | ||
22 | + } | ||
23 | + } | ||
24 | + } | ||
25 | +} |
1 | +module rock { | ||
2 | + namespace "http://example.net/rock"; | ||
3 | + prefix "rock"; | ||
4 | + | ||
5 | + rpc rock-the-house { | ||
6 | + description "description"; | ||
7 | + status current; | ||
8 | + reference "reference"; | ||
9 | + grouping hello { | ||
10 | + list valid { | ||
11 | + key invalid-interval; | ||
12 | + reference "RFC 6020"; | ||
13 | + leaf invalid-interval { | ||
14 | + type "uint16"; | ||
15 | + units "seconds"; | ||
16 | + status current; | ||
17 | + reference "RFC 6020"; | ||
18 | + } | ||
19 | + } | ||
20 | + } | ||
21 | + input { | ||
22 | + leaf zip-code { | ||
23 | + type string; | ||
24 | + } | ||
25 | + uses hello; | ||
26 | + } | ||
27 | + output { | ||
28 | + leaf status { | ||
29 | + type string; | ||
30 | + } | ||
31 | + uses hello; | ||
32 | + } | ||
33 | + } | ||
34 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + container valid { | ||
6 | + grouping endpoint { | ||
7 | + leaf zip-code { | ||
8 | + type string; | ||
9 | + } | ||
10 | + uses first; | ||
11 | + container design { | ||
12 | + uses second; | ||
13 | + container correct { | ||
14 | + leaf newone { | ||
15 | + type string; | ||
16 | + } | ||
17 | + uses third; | ||
18 | + } | ||
19 | + } | ||
20 | + uses fourth; | ||
21 | + uses fifth; | ||
22 | + } | ||
23 | + uses endpoint; | ||
24 | + grouping first { | ||
25 | + list valid { | ||
26 | + key invalid-interval; | ||
27 | + reference "RFC 6020"; | ||
28 | + leaf invalid-interval { | ||
29 | + type "uint16"; | ||
30 | + units "seconds"; | ||
31 | + status current; | ||
32 | + reference "RFC 6020"; | ||
33 | + } | ||
34 | + } | ||
35 | + } | ||
36 | + grouping second { | ||
37 | + leaf ink { | ||
38 | + type int32; | ||
39 | + } | ||
40 | + } | ||
41 | + grouping third { | ||
42 | + container value { | ||
43 | + leaf zip-code { | ||
44 | + type string; | ||
45 | + } | ||
46 | + } | ||
47 | + } | ||
48 | + grouping fourth { | ||
49 | + typedef my-type { | ||
50 | + status deprecated; | ||
51 | + type int32; | ||
52 | + } | ||
53 | + leaf correct { | ||
54 | + type my-type; | ||
55 | + } | ||
56 | + } | ||
57 | + grouping fifth { | ||
58 | + leaf abc { | ||
59 | + type string; | ||
60 | + } | ||
61 | + } | ||
62 | + } | ||
63 | +} |
1 | +module rock { | ||
2 | + namespace "http://example.net/rock"; | ||
3 | + prefix "rock"; | ||
4 | + | ||
5 | + rpc rock-the-house { | ||
6 | + description "description"; | ||
7 | + status current; | ||
8 | + reference "reference"; | ||
9 | + input { | ||
10 | + leaf zip-code { | ||
11 | + type string; | ||
12 | + } | ||
13 | + grouping creative { | ||
14 | + leaf carry { | ||
15 | + type string; | ||
16 | + } | ||
17 | + } | ||
18 | + } | ||
19 | + output { | ||
20 | + leaf status { | ||
21 | + type string; | ||
22 | + } | ||
23 | + grouping creative { | ||
24 | + list valid { | ||
25 | + key invalid-interval; | ||
26 | + leaf invalid-interval { | ||
27 | + type "uint16"; | ||
28 | + } | ||
29 | + } | ||
30 | + } | ||
31 | + typedef my-type { | ||
32 | + status deprecated; | ||
33 | + type int32; | ||
34 | + } | ||
35 | + uses creative; | ||
36 | + } | ||
37 | + } | ||
38 | +} |
... | @@ -2,6 +2,8 @@ module Test { | ... | @@ -2,6 +2,8 @@ module Test { |
2 | yang-version 1; | 2 | yang-version 1; |
3 | namespace http://huawei.com; | 3 | namespace http://huawei.com; |
4 | prefix Ant; | 4 | prefix Ant; |
5 | + grouping endpoint { | ||
6 | + } | ||
5 | container valid { | 7 | container valid { |
6 | uses endpoint { | 8 | uses endpoint { |
7 | description "grouping under test"; | 9 | description "grouping under test"; | ... | ... |
-
Please register or login to post a comment