blob: 23e190c1e263b31b4341596cca330661fecc0584 [file] [log] [blame]
Bharat saraswald14cbe82016-07-14 13:26:18 +05301/*
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
17package org.onosproject.yangutils.linker.impl;
18
Bharat saraswal039f59c2016-07-14 21:57:13 +053019import java.util.ArrayList;
20import java.util.Iterator;
21import java.util.List;
22import java.util.Set;
23import java.util.regex.Pattern;
24
VinodKumarS-Huawei423dc9a2016-08-17 22:08:42 +053025import org.onosproject.yangutils.datamodel.TraversalType;
Bharat saraswal8beac342016-08-04 02:00:03 +053026import org.onosproject.yangutils.datamodel.YangAtomicPath;
Bharat saraswald14cbe82016-07-14 13:26:18 +053027import org.onosproject.yangutils.datamodel.YangAugment;
28import org.onosproject.yangutils.datamodel.YangAugmentableNode;
janani bebb143d2016-07-14 19:35:22 +053029import org.onosproject.yangutils.datamodel.YangCase;
Bharat saraswalaf413b82016-07-14 15:18:20 +053030import org.onosproject.yangutils.datamodel.YangChoice;
VinodKumarS-Huawei423dc9a2016-08-17 22:08:42 +053031import org.onosproject.yangutils.datamodel.YangGrouping;
32import org.onosproject.yangutils.datamodel.YangIdentityRef;
Bharat saraswal039f59c2016-07-14 21:57:13 +053033import org.onosproject.yangutils.datamodel.YangImport;
34import org.onosproject.yangutils.datamodel.YangInclude;
Bharat saraswald14cbe82016-07-14 13:26:18 +053035import org.onosproject.yangutils.datamodel.YangLeaf;
36import org.onosproject.yangutils.datamodel.YangLeafList;
janani bebb143d2016-07-14 19:35:22 +053037import org.onosproject.yangutils.datamodel.YangLeafRef;
Bharat saraswald14cbe82016-07-14 13:26:18 +053038import org.onosproject.yangutils.datamodel.YangLeavesHolder;
39import org.onosproject.yangutils.datamodel.YangNode;
janani bebb143d2016-07-14 19:35:22 +053040import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
Bharat saraswal039f59c2016-07-14 21:57:13 +053041import org.onosproject.yangutils.datamodel.YangReferenceResolver;
VinodKumarS-Huawei423dc9a2016-08-17 22:08:42 +053042import org.onosproject.yangutils.datamodel.YangType;
43import org.onosproject.yangutils.datamodel.YangTypeDef;
44import org.onosproject.yangutils.datamodel.YangUses;
45import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
46import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
janani bebb143d2016-07-14 19:35:22 +053047import org.onosproject.yangutils.datamodel.utils.YangConstructType;
Bharat saraswald14cbe82016-07-14 13:26:18 +053048import org.onosproject.yangutils.linker.exceptions.LinkerException;
Bharat saraswal2da23bf2016-08-25 15:28:39 +053049import org.onosproject.yangutils.translator.exception.TranslatorException;
Bharat saraswald14cbe82016-07-14 13:26:18 +053050
VinodKumarS-Huawei423dc9a2016-08-17 22:08:42 +053051import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
52import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
53import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
54import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
55import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
Bharat saraswal2da23bf2016-08-25 15:28:39 +053056import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
Bharat saraswale3175d32016-08-31 17:50:11 +053057import static org.onosproject.yangutils.datamodel.utils.YangConstructType.getYangConstructType;
VinodKumarS-Huawei423dc9a2016-08-17 22:08:42 +053058import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
59import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
Bharat saraswal2da23bf2016-08-25 15:28:39 +053060import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangCaseNode;
janani bebb143d2016-07-14 19:35:22 +053061import static org.onosproject.yangutils.utils.UtilConstants.COLON;
62import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
janani bebb143d2016-07-14 19:35:22 +053063
Bharat saraswald14cbe82016-07-14 13:26:18 +053064/**
65 * Represent utilities for YANG linker.
66 */
67public final class YangLinkerUtils {
68
janani bebb143d2016-07-14 19:35:22 +053069 private static final int IDENTIFIER_LENGTH = 64;
70 private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*");
71 private static final String XML = "xml";
72
Bharat saraswal039f59c2016-07-14 21:57:13 +053073 private YangLinkerUtils() {
74 }
75
Bharat saraswald14cbe82016-07-14 13:26:18 +053076 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +053077 * Detects collision between target nodes leaf/leaf-list or child node with augmented leaf/leaf-list or child node.
Bharat saraswald14cbe82016-07-14 13:26:18 +053078 *
79 * @param targetNode target node
80 * @param augment augment node
81 */
82 private static void detectCollision(YangNode targetNode, YangAugment augment) {
83 YangNode targetNodesChild = targetNode.getChild();
84 YangNode augmentsChild = augment.getChild();
Bharat saraswal039f59c2016-07-14 21:57:13 +053085 YangNode parent = targetNode;
86 if (targetNode instanceof YangAugment) {
87 parent = targetNode.getParent();
Bharat saraswalaf413b82016-07-14 15:18:20 +053088 } else {
Bharat saraswal039f59c2016-07-14 21:57:13 +053089 while (parent.getParent() != null) {
90 parent = parent.getParent();
91 }
92 }
93 if (targetNode instanceof YangChoice) {
Bharat saraswal2da23bf2016-08-25 15:28:39 +053094 addCaseNodeToChoiceTarget(augment);
Bharat saraswal039f59c2016-07-14 21:57:13 +053095 } else {
96 detectCollisionInLeaveHolders(targetNode, augment);
97 while (augmentsChild != null) {
98 detectCollisionInChildNodes(targetNodesChild, augmentsChild, targetNode.getName(), parent.getName());
99 augmentsChild = augmentsChild.getNextSibling();
100 }
101 }
102 }
Bharat saraswald14cbe82016-07-14 13:26:18 +0530103
Bharat saraswal8beac342016-08-04 02:00:03 +0530104 /*Detects collision between leaves/leaf-lists*/
Bharat saraswal039f59c2016-07-14 21:57:13 +0530105 private static void detectCollisionInLeaveHolders(YangNode targetNode, YangAugment augment) {
106 YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
107 YangNode parent = targetNode;
108 if (targetNode instanceof YangAugment) {
109 parent = targetNode.getParent();
110 } else {
111 while (parent.getParent() != null) {
112 parent = parent.getParent();
113 }
114 }
115 if (augment.getListOfLeaf() != null && augment.getListOfLeaf().size() != 0
116 && targetNodesLeavesHolder.getListOfLeaf() != null) {
117 for (YangLeaf leaf : augment.getListOfLeaf()) {
118 for (YangLeaf targetLeaf : targetNodesLeavesHolder.getListOfLeaf()) {
119 if (targetLeaf.getName().equals(leaf.getName())) {
120 throw new LinkerException("target node " + targetNode.getName()
121 + " contains augmented leaf " + leaf.getName() + " in module "
Bharat saraswale3175d32016-08-31 17:50:11 +0530122 + parent.getName() + " in " + targetNode.getLineNumber()
123 + " at " + targetNode.getCharPosition() + " in " + targetNode.getFileName());
Bharat saraswal039f59c2016-07-14 21:57:13 +0530124 }
Bharat saraswald14cbe82016-07-14 13:26:18 +0530125 }
126 }
Bharat saraswal039f59c2016-07-14 21:57:13 +0530127 } else if (augment.getListOfLeafList() != null
128 && augment.getListOfLeafList().size() != 0
129 && augment.getListOfLeafList() != null) {
130 for (YangLeafList leafList : augment.getListOfLeafList()) {
131 for (YangLeafList targetLeafList : targetNodesLeavesHolder.getListOfLeafList()) {
132 if (targetLeafList.getName().equals(leafList.getName())) {
133 throw new LinkerException("target node " + targetNode.getName()
134 + " contains augmented leaf-list" + leafList.getName() + " in module "
Bharat saraswale3175d32016-08-31 17:50:11 +0530135 + parent.getName() + " in " + targetNode.getLineNumber()
136 + " at " + targetNode.getCharPosition() + " in " + targetNode.getFileName());
Bharat saraswald14cbe82016-07-14 13:26:18 +0530137 }
138 }
Bharat saraswald14cbe82016-07-14 13:26:18 +0530139 }
140 }
141 }
142
Bharat saraswal039f59c2016-07-14 21:57:13 +0530143 /*Detects collision for child nodes.*/
144 private static void detectCollisionInChildNodes(YangNode targetNodesChild, YangNode augmentsChild, String
145 targetName, String parentName) {
146 while (augmentsChild != null) {
147 while (targetNodesChild != null) {
148 if (targetNodesChild.getName().equals(augmentsChild.getName())) {
149 throw new LinkerException("target node " + targetName
Bharat saraswale3175d32016-08-31 17:50:11 +0530150 + " contains augmented child node " + augmentsChild.getName() + " in module "
151 + parentName + " in " + targetNodesChild.getLineNumber()
152 + " at " + targetNodesChild.getCharPosition() + " in " + targetNodesChild.getFileName());
Bharat saraswal039f59c2016-07-14 21:57:13 +0530153 }
154 targetNodesChild = targetNodesChild.getNextSibling();
155 }
156 augmentsChild = augmentsChild.getNextSibling();
157 }
158 }
159
Bharat saraswald14cbe82016-07-14 13:26:18 +0530160 /**
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530161 * Adds a case node in augment when augmenting a choice node.
162 *
163 * @param augment augment node
164 */
165 private static void addCaseNodeToChoiceTarget(YangAugment augment) {
166 try {
167 YangNode child = augment.getChild();
168 List<YangNode> childNodes = new ArrayList<>();
169 while (child != null) {
170 childNodes.add(child);
171 child = child.getNextSibling();
172 }
173 augment.setChild(null);
174
175 for (YangNode node : childNodes) {
176 YangCase javaCase = getYangCaseNode(JAVA_GENERATION);
177 javaCase.setName(node.getName());
178 augment.addChild(javaCase);
179 node.setParent(javaCase);
180 node.setNextSibling(null);
181 node.setPreviousSibling(null);
182 javaCase.addChild(node);
183 }
184 if (augment.getListOfLeaf() != null) {
185 for (YangLeaf leaf : augment.getListOfLeaf()) {
186 YangCase javaCase = getYangCaseNode(JAVA_GENERATION);
187 javaCase.setName(leaf.getName());
188 javaCase.addLeaf(leaf);
189 augment.addChild(javaCase);
190
191 }
192 augment.getListOfLeaf().clear();
193 }
194 if (augment.getListOfLeafList() != null) {
195 for (YangLeafList leafList : augment.getListOfLeafList()) {
196 YangCase javaCase = getYangCaseNode(JAVA_GENERATION);
197 javaCase.setName(leafList.getName());
198 javaCase.addLeafList(leafList);
199 augment.addChild(javaCase);
200 }
201 augment.getListOfLeafList().clear();
202 }
203
204 } catch (DataModelException e) {
Bharat saraswale3175d32016-08-31 17:50:11 +0530205 throw new TranslatorException("Failed to add child nodes to case node of augment " + augment.getName()
206 + " in " + augment.getLineNumber() + " at "
207 + augment.getCharPosition() + " in " + augment.getFileName());
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530208 }
209 }
210
211 //Detect collision between augment and choice children.
212 private void detectCollisionForChoiceNode(YangNode choice, YangNode augment) {
213 YangNode choiceChild = choice.getChild();
214 YangNode augmentChild = augment.getChild();
215
216 List<YangNode> choiceChildren = new ArrayList<>();
217 List<YangNode> augmentChildren = new ArrayList<>();
218 while (choiceChild != null) {
219 choiceChildren.add(choiceChild);
220 }
221 while (augmentChild != null) {
222 augmentChildren.add(augmentChild);
223 }
224
225 for (YangNode cChild : choiceChildren) {
226 for (YangNode aChild : augmentChildren) {
227 if (cChild.getName().equals(aChild.getName())) {
228 throw new LinkerException("case node " + aChild.getName() + "already present in choice " +
Bharat saraswale3175d32016-08-31 17:50:11 +0530229 choice.getName() + " in " + cChild.getLineNumber() + " at " + cChild.getCharPosition()
230 + " in " + cChild.getFileName());
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530231 }
232 }
233 }
234 }
235
236 /**
Bharat saraswalaf413b82016-07-14 15:18:20 +0530237 * Detects collision between target nodes and its all leaf/leaf-list or child node with augmented leaf/leaf-list or
238 * child node.
Bharat saraswald14cbe82016-07-14 13:26:18 +0530239 *
240 * @param targetNode target node
241 * @param augment augment node
242 */
Bharat saraswal039f59c2016-07-14 21:57:13 +0530243 static void detectCollisionForAugmentedNode(YangNode targetNode, YangAugment augment) {
Bharat saraswald14cbe82016-07-14 13:26:18 +0530244 // Detect collision for target node and augment node.
245 detectCollision(targetNode, augment);
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530246 List<YangAugment> yangAugmentedInfo = ((YangAugmentableNode) targetNode).getAugmentedInfoList();
Bharat saraswald14cbe82016-07-14 13:26:18 +0530247 // Detect collision for target augment node and current augment node.
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530248 for (YangAugment info : yangAugmentedInfo) {
249 detectCollision(info, augment);
Bharat saraswald14cbe82016-07-14 13:26:18 +0530250 }
251 }
janani bebb143d2016-07-14 19:35:22 +0530252
253 /**
254 * Returns list of path names that are needed from augment.
255 *
256 * @param augment instance of YANG augment
257 * @param remainingAncestors ancestor count to move in augment path
258 * @return list of path names needed in leafref
259 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530260 static List<String> getPathWithAugment(YangAugment augment, int remainingAncestors) {
janani bebb143d2016-07-14 19:35:22 +0530261 List<String> listOfPathName = new ArrayList<>();
Bharat saraswal8beac342016-08-04 02:00:03 +0530262 for (YangAtomicPath atomicPath : augment.getTargetNode()) {
263 if (atomicPath.getNodeIdentifier().getPrefix() != null && !atomicPath.getNodeIdentifier().getPrefix()
264 .equals(EMPTY_STRING)) {
265 listOfPathName.add(atomicPath.getNodeIdentifier().getPrefix() + ":" +
266 atomicPath.getNodeIdentifier().getName());
267 } else {
268 listOfPathName.add(atomicPath.getNodeIdentifier().getName());
janani bebb143d2016-07-14 19:35:22 +0530269 }
270 }
271 for (int countOfAncestor = 0; countOfAncestor < remainingAncestors; countOfAncestor++) {
272 listOfPathName.remove(listOfPathName.size() - 1);
273 }
274 return listOfPathName;
275 }
276
277 /**
278 * Skips the invalid nodes which cannot have data from YANG.
279 *
280 * @param currentParent current parent node reference
281 * @param leafref instance of YANG leafref
282 * @return parent node which can hold data
283 * @throws LinkerException a violation of linker rules
284 */
VinodKumarS-Huawei423dc9a2016-08-17 22:08:42 +0530285 static YangNode skipInvalidDataNodes(YangNode currentParent, YangLeafRef leafref)
286 throws LinkerException {
janani bebb143d2016-07-14 19:35:22 +0530287 while (currentParent instanceof YangChoice || currentParent instanceof YangCase) {
288 if (currentParent.getParent() == null) {
289 throw new LinkerException("YANG file error: The target node, in the leafref path " +
Bharat saraswale3175d32016-08-31 17:50:11 +0530290 leafref.getPath() + ", is invalid." + " in " + leafref.getLineNumber()
291 + " at " + leafref.getCharPosition() + " in " + leafref.getFileName());
janani bebb143d2016-07-14 19:35:22 +0530292 }
293 currentParent = currentParent.getParent();
294 }
295 return currentParent;
296 }
297
298 /**
299 * Checks and return valid node identifier.
300 *
301 * @param nodeIdentifierString string from yang file
302 * @param yangConstruct yang construct for creating error message
303 * @return valid node identifier
304 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530305 static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString,
Bharat saraswal2da23bf2016-08-25 15:28:39 +0530306 YangConstructType yangConstruct) {
janani bebb143d2016-07-14 19:35:22 +0530307 String[] tmpData = nodeIdentifierString.split(Pattern.quote(COLON));
308 if (tmpData.length == 1) {
309 YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
310 nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct));
311 return nodeIdentifier;
312 } else if (tmpData.length == 2) {
313 YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
314 nodeIdentifier.setPrefix(getValidIdentifier(tmpData[0], yangConstruct));
315 nodeIdentifier.setName(getValidIdentifier(tmpData[1], yangConstruct));
316 return nodeIdentifier;
317 } else {
318 throw new LinkerException("YANG file error : " +
Bharat saraswale3175d32016-08-31 17:50:11 +0530319 getYangConstructType(yangConstruct) + " name " + nodeIdentifierString +
janani bebb143d2016-07-14 19:35:22 +0530320 " is not valid.");
321 }
322 }
323
324 /**
325 * Validates identifier and returns concatenated string if string contains plus symbol.
326 *
327 * @param identifier string from yang file
328 * @param yangConstruct yang construct for creating error message=
329 * @return concatenated string after removing double quotes
330 */
331 public static String getValidIdentifier(String identifier, YangConstructType yangConstruct) {
332
333 if (identifier.length() > IDENTIFIER_LENGTH) {
334 throw new LinkerException("YANG file error : " +
Bharat saraswale3175d32016-08-31 17:50:11 +0530335 getYangConstructType(yangConstruct) + " name " + identifier + " is " +
janani bebb143d2016-07-14 19:35:22 +0530336 "greater than 64 characters.");
337 } else if (!IDENTIFIER_PATTERN.matcher(identifier).matches()) {
338 throw new LinkerException("YANG file error : " +
Bharat saraswale3175d32016-08-31 17:50:11 +0530339 getYangConstructType(yangConstruct) + " name " + identifier + " is not " +
janani bebb143d2016-07-14 19:35:22 +0530340 "valid.");
341 } else if (identifier.toLowerCase().startsWith(XML)) {
342 throw new LinkerException("YANG file error : " +
Bharat saraswale3175d32016-08-31 17:50:11 +0530343 getYangConstructType(yangConstruct) + " identifier " + identifier +
janani bebb143d2016-07-14 19:35:22 +0530344 " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
345 } else {
346 return identifier;
347 }
348 }
Bharat saraswal039f59c2016-07-14 21:57:13 +0530349
350 /**
351 * Updates the priority for all the input files.
352 *
353 * @param yangNodeSet set of YANG files info
354 */
355 public static void updateFilePriority(Set<YangNode> yangNodeSet) {
356 for (YangNode yangNode : yangNodeSet) {
357 updateFilePriorityOfNode(yangNode);
358 }
359 }
360
361 /**
362 * Updates priority of the node.
363 *
364 * @param yangNode YANG node information
365 */
Bharat saraswal8beac342016-08-04 02:00:03 +0530366 private static void updateFilePriorityOfNode(YangNode yangNode) {
Bharat saraswal039f59c2016-07-14 21:57:13 +0530367 int curNodePriority = yangNode.getPriority();
368 if (yangNode instanceof YangReferenceResolver) {
369 List<YangImport> yangImportList = ((YangReferenceResolver) yangNode).getImportList();
370 Iterator<YangImport> importInfoIterator = yangImportList.iterator();
371 // Run through the imported list to update priority.
372 while (importInfoIterator.hasNext()) {
373 YangImport yangImport = importInfoIterator.next();
374 YangNode importedNode = yangImport.getImportedNode();
375 if (curNodePriority >= importedNode.getPriority()) {
376 importedNode.setPriority(curNodePriority + 1);
377 updateFilePriorityOfNode(importedNode);
378 }
379 }
380
381 List<YangInclude> yangIncludeList = ((YangReferenceResolver) yangNode).getIncludeList();
382 Iterator<YangInclude> includeInfoIterator = yangIncludeList.iterator();
383 // Run through the imported list to update priority.
384 while (includeInfoIterator.hasNext()) {
385 YangInclude yangInclude = includeInfoIterator.next();
386 YangNode includedNode = yangInclude.getIncludedNode();
387 if (curNodePriority >= includedNode.getPriority()) {
388 includedNode.setPriority(curNodePriority + 1);
389 updateFilePriorityOfNode(includedNode);
390 }
391 }
392 }
393 }
VinodKumarS-Huawei423dc9a2016-08-17 22:08:42 +0530394
395 /**
396 * Add the unresolved data under the root leve grouping to be resolved, since it will be used in interfile uses.
397 *
398 * @param referenceResolver module / sub-module
399 */
400 public static void resolveGroupingInDefinationScope(YangReferenceResolver referenceResolver) {
401 YangNode potentialInterFileGrouping = ((YangNode) referenceResolver).getChild();
402
403 while (potentialInterFileGrouping != null) {
404 if (potentialInterFileGrouping instanceof YangGrouping) {
405 addGroupingResolvableEntitiesToResolutionList((YangGrouping) potentialInterFileGrouping);
406 }
407
408 potentialInterFileGrouping = potentialInterFileGrouping.getNextSibling();
409 }
410 }
411
412 /**
413 * Add the interfile grouping resolvable entities to reesolution list.
414 *
415 * @param interFileGrouping interfile grouping
416 */
417 private static void addGroupingResolvableEntitiesToResolutionList(YangGrouping interFileGrouping) {
418 YangNode curNode = interFileGrouping;
419 TraversalType curTraversal = ROOT;
420 addResolvableLeavesToResolutionList((YangLeavesHolder) curNode);
421 curTraversal = CHILD;
422 curNode = interFileGrouping.getChild();
423 if (curNode == null) {
424 return;
425 }
426 while (curNode != interFileGrouping) {
427 if (curTraversal != PARENT) {
428 if (curNode instanceof YangGrouping || curNode instanceof YangUses) {
429 if (curNode.getNextSibling() != null) {
430 curTraversal = SIBILING;
431 curNode = curNode.getNextSibling();
432 } else {
433 curTraversal = PARENT;
434 curNode = curNode.getParent();
435 }
436 continue;
437 }
438
439 if (curNode instanceof YangLeavesHolder) {
440 addResolvableLeavesToResolutionList((YangLeavesHolder) curNode);
441 } else if (curNode instanceof YangTypeDef) {
442 List<YangType<?>> typeList = ((YangTypeDef) curNode).getTypeList();
443 if (!typeList.isEmpty()) {
444 YangType<?> type = typeList.get(0);
445 if (type.getDataType() == DERIVED) {
446 if (type.getResolvableStatus() != ResolvableStatus.RESOLVED) {
447
448 type.setTypeForInterFileGroupingResolution(true);
449
450 // Add resolution information to the list
451 YangResolutionInfoImpl resolutionInfo =
452 new YangResolutionInfoImpl<YangType>(type, curNode, type.getLineNumber(),
453 type.getCharPosition());
454 try {
455 addResolutionInfo(resolutionInfo);
456 } catch (DataModelException e) {
Bharat saraswale3175d32016-08-31 17:50:11 +0530457 String errorInfo = "Error in file: " + curNode.getName() + " in " +
458 curNode.getFileName() + " at " +
459 "line: " + e.getLineNumber() +
460 " at position: " + e.getCharPositionInLine()
461 + e.getLocalizedMessage();
462 throw new LinkerException("Failed to add type info in grouping to resolution "
463 + errorInfo);
VinodKumarS-Huawei423dc9a2016-08-17 22:08:42 +0530464 }
465 }
466 }
467 }
468 }
469
470 }
471 if (curTraversal != PARENT && curNode.getChild() != null) {
472 curTraversal = CHILD;
473 curNode = curNode.getChild();
474 } else if (curNode.getNextSibling() != null) {
475
476 curTraversal = SIBILING;
477 curNode = curNode.getNextSibling();
478 } else {
479 curTraversal = PARENT;
480 curNode = curNode.getParent();
481 }
482 }
483 }
484
485 /**
486 * Add resolvable leaves type info to resolution list.
487 *
488 * @param leavesHolder leaves holder node
489 */
490 private static void addResolvableLeavesToResolutionList(YangLeavesHolder leavesHolder) {
491 if (leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()) {
492 for (YangLeaf leaf : leavesHolder.getListOfLeaf()) {
493 YangType type = leaf.getDataType();
494 if (type.getDataType() == DERIVED) {
495
496 type.setTypeForInterFileGroupingResolution(true);
497
498 // Add resolution information to the list
499 YangResolutionInfoImpl resolutionInfo =
Bharat saraswale3175d32016-08-31 17:50:11 +0530500 new YangResolutionInfoImpl<>(type, (YangNode) leavesHolder,
VinodKumarS-Huawei423dc9a2016-08-17 22:08:42 +0530501 type.getLineNumber(), type.getCharPosition());
502 try {
503 addResolutionInfo(resolutionInfo);
504 } catch (DataModelException e) {
505 throw new LinkerException("Failed to add leaf type info in grouping, to resolution ");
506 }
507 } else if (type.getDataType() == IDENTITYREF) {
508 YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
509
510 identityRef.setIdentityForInterFileGroupingResolution(true);
511
512 // Add resolution information to the list
513 YangResolutionInfoImpl resolutionInfo =
514 new YangResolutionInfoImpl<YangIdentityRef>(identityRef, (YangNode) leavesHolder,
515 identityRef.getLineNumber(), identityRef.getCharPosition());
516 try {
517 addResolutionInfo(resolutionInfo);
518 } catch (DataModelException e) {
519 throw new LinkerException("Failed to add leaf identity ref info in grouping, to resolution ");
520 }
521 }
522 }
523 }
524
525 if (leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty()) {
526 for (YangLeafList leafList : leavesHolder.getListOfLeafList()) {
527 YangType type = leafList.getDataType();
528 if (type.getDataType() == DERIVED) {
529
530 type.setTypeForInterFileGroupingResolution(true);
531
532 // Add resolution information to the list
533 YangResolutionInfoImpl resolutionInfo =
534 new YangResolutionInfoImpl<YangType>(type, (YangNode) leavesHolder,
535 type.getLineNumber(), type.getCharPosition());
536 try {
537 addResolutionInfo(resolutionInfo);
538 } catch (DataModelException e) {
539 throw new LinkerException("Failed to add leaf type info in grouping, to resolution ");
540 }
541 } else if (type.getDataType() == IDENTITYREF) {
542 YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
543
544 identityRef.setIdentityForInterFileGroupingResolution(true);
545 // Add resolution information to the list
546 YangResolutionInfoImpl resolutionInfo =
547 new YangResolutionInfoImpl<YangIdentityRef>(identityRef, (YangNode) leavesHolder,
548 identityRef.getLineNumber(), identityRef.getCharPosition());
549 try {
550 addResolutionInfo(resolutionInfo);
551 } catch (DataModelException e) {
552 throw new LinkerException("Failed to add leaf identity ref info in grouping, to resolution ");
553 }
554 }
555 }
556 }
557 }
558
Bharat saraswald14cbe82016-07-14 13:26:18 +0530559}