[ONOS-4993] [ONOS-4956] [ONOS-4935] YANG interfile linker defect fix
Change-Id: I0037c9bd2a73b13a50bb874c7a72c6b2f5050e7e
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIdentityRef.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIdentityRef.java
index 65a0545..d4e3065 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIdentityRef.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangIdentityRef.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
+
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
@@ -43,7 +44,9 @@
/**
* Represents data model node to maintain information defined in YANG identityref.
*/
-public class YangIdentityRef extends YangNode implements Parsable, Resolvable, Serializable {
+public class YangIdentityRef
+ extends YangNode
+ implements Parsable, Resolvable, Serializable, LocationInfo {
private static final long serialVersionUID = 806201692L;
@@ -61,6 +64,17 @@
*/
private ResolvableStatus resolvableStatus;
+ /**
+ * Resolution for interfile grouping.
+ */
+ private boolean isIdentityForInterFileGroupingResolution;
+
+ // Error line number.
+ private transient int lineNumber;
+
+ // Error character position in number.
+ private transient int charPositionInLine;
+
// Creates a specific identityref of node.
public YangIdentityRef() {
super(YangNodeType.IDENTITYREF_NODE, null);
@@ -70,7 +84,7 @@
@Override
public void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
- YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
throws DataModelException {
// Do nothing.
}
@@ -101,7 +115,8 @@
}
@Override
- public Object resolve() throws DataModelException {
+ public Object resolve()
+ throws DataModelException {
// Check if the derived info is present.
YangIdentity identity = getReferredIdentity();
@@ -191,11 +206,13 @@
}
@Override
- public void validateDataOnEntry() throws DataModelException {
+ public void validateDataOnEntry()
+ throws DataModelException {
}
@Override
- public void validateDataOnExit() throws DataModelException {
+ public void validateDataOnExit()
+ throws DataModelException {
}
/**
@@ -215,4 +232,33 @@
public void setReferredIdentity(YangIdentity referredIdentity) {
this.referredIdentity = referredIdentity;
}
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public int getCharPosition() {
+ return charPositionInLine;
+ }
+
+ @Override
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ @Override
+ public void setCharPosition(int charPositionInLine) {
+ this.charPositionInLine = charPositionInLine;
+ }
+
+ public boolean isIdentityForInterFileGroupingResolution() {
+ return isIdentityForInterFileGroupingResolution;
+ }
+
+ public void setIdentityForInterFileGroupingResolution(boolean identityForInterFileGroupingResolution) {
+ isIdentityForInterFileGroupingResolution = identityForInterFileGroupingResolution;
+ }
+
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangType.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
index ca442e6..80c53ec 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
@@ -64,7 +64,7 @@
* @param <T> YANG data type info
*/
public class YangType<T>
- implements Parsable, Resolvable, Serializable {
+ implements Parsable, Resolvable, Serializable, LocationInfo {
private static final long serialVersionUID = 8062016054L;
@@ -93,6 +93,29 @@
*/
private ResolvableStatus resolvableStatus;
+
+ /**
+ * Resolution for interfile grouping.
+ */
+ private boolean isTypeForInterFileGroupingResolution;
+
+ /**
+ * Resolved within the grouping where the type is used.
+ */
+ private boolean isTypeNotResolvedTillRootNode;
+
+
+ /**
+ * Error line number.
+ */
+ private transient int lineNumber;
+
+ /**
+ * Error character position in number.
+ */
+ private transient int charPositionInLine;
+
+
/**
* Creates a YANG type object.
*/
@@ -276,7 +299,8 @@
* @param value input data value
* @throws DataModelException a violation of data model rules
*/
- void isValidValue(String value) throws DataModelException {
+ void isValidValue(String value)
+ throws DataModelException {
switch (getDataType()) {
case INT8:
case INT16:
@@ -501,4 +525,40 @@
return isMatched;
}
+
+ @Override
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ @Override
+ public int getCharPosition() {
+ return charPositionInLine;
+ }
+
+ @Override
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ @Override
+ public void setCharPosition(int charPositionInLine) {
+ this.charPositionInLine = charPositionInLine;
+ }
+
+ public boolean isTypeForInterFileGroupingResolution() {
+ return isTypeForInterFileGroupingResolution;
+ }
+
+ public void setTypeForInterFileGroupingResolution(boolean typeForInterFileGroupingResolution) {
+ isTypeForInterFileGroupingResolution = typeForInterFileGroupingResolution;
+ }
+
+ public boolean isTypeNotResolvedTillRootNode() {
+ return isTypeNotResolvedTillRootNode;
+ }
+
+ public void setTypeNotResolvedTillRootNode(boolean typeNotResolvedTillRootNode) {
+ isTypeNotResolvedTillRootNode = typeNotResolvedTillRootNode;
+ }
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
index db0eeb9..42e4237 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
@@ -28,8 +28,8 @@
import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeaf;
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLeafrefUnderGroupingForLeafList;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveYangConstructsUnderGroupingForLeaf;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveYangConstructsUnderGroupingForLeafList;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef;
/*-
@@ -408,8 +408,8 @@
YangConstructType.LEAF_DATA);
clonedLeaf = leaf.clone();
if (getCurrentGroupingDepth() == 0) {
- YangEntityToResolveInfoImpl resolveInfo = resolveLeafrefUnderGroupingForLeaf(clonedLeaf,
- usesParentLeavesHolder, this);
+ YangEntityToResolveInfoImpl resolveInfo = resolveYangConstructsUnderGroupingForLeaf(
+ clonedLeaf, usesParentLeavesHolder, this);
if (resolveInfo != null) {
addEntityToResolve(resolveInfo);
}
@@ -431,7 +431,8 @@
clonedLeafList = leafList.clone();
if (getCurrentGroupingDepth() == 0) {
YangEntityToResolveInfoImpl resolveInfo =
- resolveLeafrefUnderGroupingForLeafList(clonedLeafList, usesParentLeavesHolder);
+ resolveYangConstructsUnderGroupingForLeafList(clonedLeafList,
+ usesParentLeavesHolder, this);
if (resolveInfo != null) {
addEntityToResolve(resolveInfo);
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index 29896ef..9547e78 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -226,7 +226,7 @@
* @throws DataModelException a violation of data model rules
*/
public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
- YangReferenceResolver dataModelRootNode)
+ YangReferenceResolver dataModelRootNode)
throws DataModelException {
for (YangResolutionInfo resolutionInfo : resolutionList) {
@@ -242,7 +242,7 @@
* @throws DataModelException a violation of data model rules
*/
public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList,
- YangReferenceResolver dataModelRootNode)
+ YangReferenceResolver dataModelRootNode)
throws DataModelException {
/*
* Run through the resolution list, find type/uses referring to inter
@@ -313,7 +313,8 @@
* @return de-serializes YANG data-model nodes
* @throws IOException when fails do IO operations
*/
- public static YangNode deSerializeDataModel(String serializedFileInfo) throws IOException {
+ public static YangNode deSerializeDataModel(String serializedFileInfo)
+ throws IOException {
YangNode node;
try {
@@ -346,7 +347,7 @@
YangLeaf clonedLeaf = leaf.clone();
if (yangUses.getCurrentGroupingDepth() == 0) {
YangEntityToResolveInfoImpl resolveInfo =
- resolveLeafrefUnderGroupingForLeaf(clonedLeaf, leavesHolder, yangUses);
+ resolveYangConstructsUnderGroupingForLeaf(clonedLeaf, leavesHolder, yangUses);
if (resolveInfo != null) {
yangUses.addEntityToResolve(resolveInfo);
}
@@ -364,7 +365,8 @@
YangLeafList clonedLeafList = leafList.clone();
if (yangUses.getCurrentGroupingDepth() == 0) {
YangEntityToResolveInfoImpl resolveInfo =
- resolveLeafrefUnderGroupingForLeafList(clonedLeafList, leavesHolder);
+ resolveYangConstructsUnderGroupingForLeafList(clonedLeafList, leavesHolder,
+ yangUses);
if (resolveInfo != null) {
yangUses.addEntityToResolve(resolveInfo);
}
@@ -386,8 +388,9 @@
* @throws DataModelException data model error
*/
public static YangEntityToResolveInfoImpl resolveLeafrefUnderGroupingForLeaf(YangLeaf clonedLeaf,
- YangLeavesHolder leafParentHolder,
- YangUses yangUses) throws
+ YangLeavesHolder leafParentHolder,
+ YangUses yangUses)
+ throws
DataModelException {
if (clonedLeaf.getDataType().getDataTypeExtendedInfo() instanceof YangLeafRef) {
YangLeafRef leafrefForCloning = (YangLeafRef) clonedLeaf.getDataType().getDataTypeExtendedInfo();
@@ -405,14 +408,123 @@
}
/**
+ * Resolves leafRef, identityRef and derived type in leaf, which are under grouping by adding it to the resolution
+ * list.
+ *
+ * @param clonedLeaf cloned leaf in uses from grouping
+ * @param leafParentHolder holder of the leaf from uses
+ * @param yangUses YANG uses
+ * @return entity of leafRef/identityRef/derived type which has to be resolved
+ * @throws DataModelException data model error
+ */
+ public static YangEntityToResolveInfoImpl resolveYangConstructsUnderGroupingForLeaf(YangLeaf clonedLeaf,
+ YangLeavesHolder leafParentHolder, YangUses yangUses)
+ throws DataModelException {
+ int lineNumber;
+ int charPosition;
+ YangDataTypes dataTypes = clonedLeaf.getDataType().getDataType();
+ YangEntityToResolveInfoImpl yangEntityToResolveInfo = new YangEntityToResolveInfoImpl();
+ switch (dataTypes) {
+ case LEAFREF:
+ YangLeafRef leafRefForCloning = (YangLeafRef) clonedLeaf.getDataType().getDataTypeExtendedInfo();
+ // Conversion of prefixes in absolute path while cloning them.
+ convertThePrefixesDuringChange(leafRefForCloning, yangUses);
+ leafRefForCloning.setParentNodeOfLeafref((YangNode) leafParentHolder);
+ yangEntityToResolveInfo.setEntityToResolve(leafRefForCloning);
+ lineNumber = leafRefForCloning.getCharPosition();
+ charPosition = leafRefForCloning.getLineNumber();
+ break;
+ case IDENTITYREF:
+ YangIdentityRef identityRef = (YangIdentityRef) clonedLeaf.getDataType().getDataTypeExtendedInfo();
+ if (identityRef.isIdentityForInterFileGroupingResolution()) {
+ return null;
+ }
+ yangEntityToResolveInfo.setEntityToResolve(identityRef);
+ lineNumber = identityRef.getCharPosition();
+ charPosition = identityRef.getLineNumber();
+ break;
+ case DERIVED:
+ YangType type = clonedLeaf.getDataType();
+ if (type.isTypeForInterFileGroupingResolution()) {
+ return null;
+ }
+ yangEntityToResolveInfo.setEntityToResolve(type);
+ lineNumber = type.getCharPosition();
+ charPosition = type.getLineNumber();
+ break;
+ default:
+ return null;
+ }
+ yangEntityToResolveInfo.setHolderOfEntityToResolve((YangNode) leafParentHolder);
+ yangEntityToResolveInfo.setCharPosition(charPosition);
+ yangEntityToResolveInfo.setLineNumber(lineNumber);
+ return yangEntityToResolveInfo;
+ }
+
+ /**
+ * Resolves leafRef, identityRef and derived type in leaf-list, which are under grouping by adding it to the
+ * resolution list.
+ *
+ * @param clonedLeafList cloned leaf-list in uses from grouping
+ * @param leafParentHolder holder of the leaf from uses
+ * @param yangUses YANG uses
+ * @return entity of leafRef/identityRef/derived type which has to be resolved
+ * @throws DataModelException data model error
+ */
+ public static YangEntityToResolveInfoImpl resolveYangConstructsUnderGroupingForLeafList(
+ YangLeafList clonedLeafList, YangLeavesHolder leafParentHolder, YangUses yangUses)
+ throws DataModelException {
+ int lineNumber;
+ int charPosition;
+ YangDataTypes dataTypes = clonedLeafList.getDataType().getDataType();
+ YangEntityToResolveInfoImpl yangEntityToResolveInfo = new YangEntityToResolveInfoImpl();
+ switch (dataTypes) {
+ case LEAFREF:
+ YangLeafRef leafRefForCloning = (YangLeafRef) clonedLeafList.getDataType().getDataTypeExtendedInfo();
+ // Conversion of prefixes in absolute path while cloning them.
+ convertThePrefixesDuringChange(leafRefForCloning, yangUses);
+ leafRefForCloning.setParentNodeOfLeafref((YangNode) leafParentHolder);
+ yangEntityToResolveInfo.setEntityToResolve(leafRefForCloning);
+ lineNumber = leafRefForCloning.getCharPosition();
+ charPosition = leafRefForCloning.getLineNumber();
+ break;
+ case IDENTITYREF:
+ YangIdentityRef identityRef = (YangIdentityRef) clonedLeafList.getDataType().getDataTypeExtendedInfo();
+
+ if (identityRef.isIdentityForInterFileGroupingResolution()) {
+ return null;
+ }
+ yangEntityToResolveInfo.setEntityToResolve(identityRef);
+ lineNumber = identityRef.getCharPosition();
+ charPosition = identityRef.getLineNumber();
+ break;
+ case DERIVED:
+ YangType type = clonedLeafList.getDataType();
+ if (type.isTypeForInterFileGroupingResolution() && type.isTypeNotResolvedTillRootNode()) {
+ return null;
+ }
+ yangEntityToResolveInfo.setEntityToResolve(type);
+ lineNumber = type.getCharPosition();
+ charPosition = type.getLineNumber();
+ break;
+ default:
+ return null;
+ }
+ yangEntityToResolveInfo.setHolderOfEntityToResolve((YangNode) leafParentHolder);
+ yangEntityToResolveInfo.setCharPosition(charPosition);
+ yangEntityToResolveInfo.setLineNumber(lineNumber);
+ return yangEntityToResolveInfo;
+ }
+
+ /**
* Converts the prefixes in all the nodes of the leafref with respect to the uses node.
*
* @param leafrefForCloning leafref that is to be cloned
* @param yangUses instance of YANG uses where cloning is done
* @throws DataModelException data model error
*/
- private static void convertThePrefixesDuringChange(YangLeafRef leafrefForCloning, YangUses yangUses) throws
- DataModelException {
+ private static void convertThePrefixesDuringChange(YangLeafRef leafrefForCloning, YangUses yangUses)
+ throws DataModelException {
List<YangAtomicPath> atomicPathList = leafrefForCloning.getAtomicPath();
if (atomicPathList != null && !atomicPathList.isEmpty()) {
Iterator<YangAtomicPath> atomicPathIterator = atomicPathList.listIterator();
@@ -435,7 +547,8 @@
* @throws DataModelException data model error
*/
private static void assignCurrentLeafedWithNewPrefixes(String importedNodeName, YangAtomicPath atomicPath,
- YangNode node) throws DataModelException {
+ YangNode node)
+ throws DataModelException {
while (!(node instanceof YangReferenceResolver)) {
node = node.getParent();
if (node == null) {
@@ -457,38 +570,14 @@
}
/**
- * Resolves leafref in leaf-list, which are under grouping by adding it to the resolution list.
- *
- * @param clonedLeafList cloned leaf-list in uses from grouping
- * @param leafListParentHolder holder of the leaf-list from uses
- * @return entity of leafref which has to be resolved
- * @throws DataModelException data model error
- */
- public static YangEntityToResolveInfoImpl resolveLeafrefUnderGroupingForLeafList(YangLeafList clonedLeafList,
- YangLeavesHolder
- leafListParentHolder)
- throws DataModelException {
- if (clonedLeafList.getDataType().getDataTypeExtendedInfo() instanceof YangLeafRef) {
- YangLeafRef leafrefForCloning = (YangLeafRef) clonedLeafList.getDataType().getDataTypeExtendedInfo();
- leafrefForCloning.setParentNodeOfLeafref((YangNode) leafListParentHolder);
- YangEntityToResolveInfoImpl yangEntityToResolveInfo = new YangEntityToResolveInfoImpl();
- yangEntityToResolveInfo.setEntityToResolve(leafrefForCloning);
- yangEntityToResolveInfo.setHolderOfEntityToResolve((YangNode) leafListParentHolder);
- yangEntityToResolveInfo.setLineNumber(leafrefForCloning.getLineNumber());
- yangEntityToResolveInfo.setCharPosition(leafrefForCloning.getCharPosition());
- return yangEntityToResolveInfo;
- }
- return null;
- }
-
- /**
* Clones the union or enum leaves. If there is any cloned leaves whose type is union/enum then the corresponding
* type info needs to be updated to the cloned new type node.
*
* @param leavesHolder cloned leaves holder, for whom the leaves reference needs to be updated
* @throws DataModelException when fails to do data model operations
*/
- public static void updateClonedLeavesUnionEnumRef(YangLeavesHolder leavesHolder) throws DataModelException {
+ public static void updateClonedLeavesUnionEnumRef(YangLeavesHolder leavesHolder)
+ throws DataModelException {
List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf();
if (currentListOfLeaves != null) {
for (YangLeaf leaf : currentListOfLeaves) {
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
index 17c3238..641af4c 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
@@ -21,6 +21,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
@@ -115,7 +116,8 @@
* @param yangNodeSet set of YANG files info
* @throws LinkerException fails to find imported module
*/
- public void addRefToYangFilesImportList(Set<YangNode> yangNodeSet) throws LinkerException {
+ public void addRefToYangFilesImportList(Set<YangNode> yangNodeSet)
+ throws LinkerException {
for (YangNode yangNode : yangNodeSet) {
if (yangNode instanceof YangReferenceResolver) {
try {
@@ -137,7 +139,8 @@
* @param yangNodeSet set of YANG files info
* @throws LinkerException fails to find included sub-module
*/
- public void addRefToYangFilesIncludeList(Set<YangNode> yangNodeSet) throws LinkerException {
+ public void addRefToYangFilesIncludeList(Set<YangNode> yangNodeSet)
+ throws LinkerException {
for (YangNode yangNode : yangNodeSet) {
if (yangNode instanceof YangReferenceResolver) {
try {
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
index c9fedd8..fb80076 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
@@ -22,12 +22,15 @@
import java.util.Set;
import java.util.regex.Pattern;
+import org.onosproject.yangutils.datamodel.TraversalType;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
+import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangLeaf;
@@ -37,9 +40,21 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
+import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
+import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
+import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
@@ -187,7 +202,8 @@
* @return parent node which can hold data
* @throws LinkerException a violation of linker rules
*/
- static YangNode skipInvalidDataNodes(YangNode currentParent, YangLeafRef leafref) throws LinkerException {
+ static YangNode skipInvalidDataNodes(YangNode currentParent, YangLeafRef leafref)
+ throws LinkerException {
while (currentParent instanceof YangChoice || currentParent instanceof YangCase) {
if (currentParent.getParent() == null) {
throw new LinkerException("YANG file error: The target node, in the leafref path " +
@@ -206,7 +222,7 @@
* @return valid node identifier
*/
static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString,
- YangConstructType yangConstruct) {
+ YangConstructType yangConstruct) {
String[] tmpData = nodeIdentifierString.split(Pattern.quote(COLON));
if (tmpData.length == 1) {
YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
@@ -294,4 +310,163 @@
}
}
}
+
+ /**
+ * Add the unresolved data under the root leve grouping to be resolved, since it will be used in interfile uses.
+ *
+ * @param referenceResolver module / sub-module
+ */
+ public static void resolveGroupingInDefinationScope(YangReferenceResolver referenceResolver) {
+ YangNode potentialInterFileGrouping = ((YangNode) referenceResolver).getChild();
+
+ while (potentialInterFileGrouping != null) {
+ if (potentialInterFileGrouping instanceof YangGrouping) {
+ addGroupingResolvableEntitiesToResolutionList((YangGrouping) potentialInterFileGrouping);
+ }
+
+ potentialInterFileGrouping = potentialInterFileGrouping.getNextSibling();
+ }
+ }
+
+ /**
+ * Add the interfile grouping resolvable entities to reesolution list.
+ *
+ * @param interFileGrouping interfile grouping
+ */
+ private static void addGroupingResolvableEntitiesToResolutionList(YangGrouping interFileGrouping) {
+ YangNode curNode = interFileGrouping;
+ TraversalType curTraversal = ROOT;
+ addResolvableLeavesToResolutionList((YangLeavesHolder) curNode);
+ curTraversal = CHILD;
+ curNode = interFileGrouping.getChild();
+ if (curNode == null) {
+ return;
+ }
+ while (curNode != interFileGrouping) {
+ if (curTraversal != PARENT) {
+ if (curNode instanceof YangGrouping || curNode instanceof YangUses) {
+ if (curNode.getNextSibling() != null) {
+ curTraversal = SIBILING;
+ curNode = curNode.getNextSibling();
+ } else {
+ curTraversal = PARENT;
+ curNode = curNode.getParent();
+ }
+ continue;
+ }
+
+ if (curNode instanceof YangLeavesHolder) {
+ addResolvableLeavesToResolutionList((YangLeavesHolder) curNode);
+ } else if (curNode instanceof YangTypeDef) {
+ List<YangType<?>> typeList = ((YangTypeDef) curNode).getTypeList();
+ if (!typeList.isEmpty()) {
+ YangType<?> type = typeList.get(0);
+ if (type.getDataType() == DERIVED) {
+ if (type.getResolvableStatus() != ResolvableStatus.RESOLVED) {
+
+ type.setTypeForInterFileGroupingResolution(true);
+
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo =
+ new YangResolutionInfoImpl<YangType>(type, curNode, type.getLineNumber(),
+ type.getCharPosition());
+ try {
+ addResolutionInfo(resolutionInfo);
+ } catch (DataModelException e) {
+ throw new LinkerException("Failed to add type info in grouping to resolution ");
+ }
+ }
+ }
+ }
+ }
+
+ }
+ if (curTraversal != PARENT && curNode.getChild() != null) {
+ curTraversal = CHILD;
+ curNode = curNode.getChild();
+ } else if (curNode.getNextSibling() != null) {
+
+ curTraversal = SIBILING;
+ curNode = curNode.getNextSibling();
+ } else {
+ curTraversal = PARENT;
+ curNode = curNode.getParent();
+ }
+ }
+ }
+
+ /**
+ * Add resolvable leaves type info to resolution list.
+ *
+ * @param leavesHolder leaves holder node
+ */
+ private static void addResolvableLeavesToResolutionList(YangLeavesHolder leavesHolder) {
+ if (leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()) {
+ for (YangLeaf leaf : leavesHolder.getListOfLeaf()) {
+ YangType type = leaf.getDataType();
+ if (type.getDataType() == DERIVED) {
+
+ type.setTypeForInterFileGroupingResolution(true);
+
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo =
+ new YangResolutionInfoImpl<YangType>(type, (YangNode) leavesHolder,
+ type.getLineNumber(), type.getCharPosition());
+ try {
+ addResolutionInfo(resolutionInfo);
+ } catch (DataModelException e) {
+ throw new LinkerException("Failed to add leaf type info in grouping, to resolution ");
+ }
+ } else if (type.getDataType() == IDENTITYREF) {
+ YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
+
+ identityRef.setIdentityForInterFileGroupingResolution(true);
+
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo =
+ new YangResolutionInfoImpl<YangIdentityRef>(identityRef, (YangNode) leavesHolder,
+ identityRef.getLineNumber(), identityRef.getCharPosition());
+ try {
+ addResolutionInfo(resolutionInfo);
+ } catch (DataModelException e) {
+ throw new LinkerException("Failed to add leaf identity ref info in grouping, to resolution ");
+ }
+ }
+ }
+ }
+
+ if (leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty()) {
+ for (YangLeafList leafList : leavesHolder.getListOfLeafList()) {
+ YangType type = leafList.getDataType();
+ if (type.getDataType() == DERIVED) {
+
+ type.setTypeForInterFileGroupingResolution(true);
+
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo =
+ new YangResolutionInfoImpl<YangType>(type, (YangNode) leavesHolder,
+ type.getLineNumber(), type.getCharPosition());
+ try {
+ addResolutionInfo(resolutionInfo);
+ } catch (DataModelException e) {
+ throw new LinkerException("Failed to add leaf type info in grouping, to resolution ");
+ }
+ } else if (type.getDataType() == IDENTITYREF) {
+ YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
+
+ identityRef.setIdentityForInterFileGroupingResolution(true);
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo =
+ new YangResolutionInfoImpl<YangIdentityRef>(identityRef, (YangNode) leavesHolder,
+ identityRef.getLineNumber(), identityRef.getCharPosition());
+ try {
+ addResolutionInfo(resolutionInfo);
+ } catch (DataModelException e) {
+ throw new LinkerException("Failed to add leaf identity ref info in grouping, to resolution ");
+ }
+ }
+ }
+ }
+ }
+
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
index f338672..00fb699 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
@@ -21,6 +21,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
+
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.TraversalType;
@@ -286,7 +287,8 @@
* Adds the leafref/identityref type to the type, which has derived type referring to
* typedef with leafref/identityref type.
*/
- private void addDerivedRefTypeToRefTypeResolutionList() throws DataModelException {
+ private void addDerivedRefTypeToRefTypeResolutionList()
+ throws DataModelException {
YangNode potentialAncestorWithReferredNode = getEntityToResolveInfo().getHolderOfEntityToResolve();
@@ -377,7 +379,7 @@
if (entityToResolve != null && !entityToResolve.isEmpty()) {
Iterator<T> entityToResolveIterator = entityToResolve.listIterator();
while (entityToResolveIterator.hasNext()) {
- addUnresolvedEntitiesToStack(entityToResolveIterator.next());
+ addUnresolvedEntitiesToResolutionList(entityToResolveIterator.next());
}
}
if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != INTRA_FILE_RESOLVED
@@ -393,7 +395,8 @@
* @param entityToResolve entity to resolve
* @throws DataModelException a violation of data model rules
*/
- private void addUnresolvedEntitiesToStack(T entityToResolve) throws DataModelException {
+ private void addUnresolvedEntitiesToResolutionList(T entityToResolve)
+ throws DataModelException {
if (entityToResolve instanceof YangEntityToResolveInfoImpl) {
YangEntityToResolveInfoImpl entityToResolveInfo = (YangEntityToResolveInfoImpl) entityToResolve;
if (entityToResolveInfo.getEntityToResolve() instanceof YangLeafRef) {
@@ -403,12 +406,13 @@
if (leafref.getResolvableStatus() == UNRESOLVED) {
leafref.setResolvableStatus(INTRA_FILE_RESOLVED);
}
- // Add resolution information to the list.
- YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<YangLeafRef>(leafref,
- parentNodeOfLeafref, entityToResolveInfo.getLineNumber(),
- entityToResolveInfo.getCharPosition());
- addResolutionInfo(resolutionInfoImpl);
}
+
+ // Add resolution information to the list.
+ YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(
+ entityToResolveInfo.getEntityToResolve(), entityToResolveInfo.getHolderOfEntityToResolve(),
+ entityToResolveInfo.getLineNumber(), entityToResolveInfo.getCharPosition());
+ addResolutionInfo(resolutionInfoImpl);
}
}
@@ -450,6 +454,11 @@
return;
} else {
+ YangType type = null;
+ if (getCurrentEntityToResolveFromStack() instanceof YangType) {
+ type = (YangType) getCurrentEntityToResolveFromStack();
+ }
+
/**
* Traverse up in the ancestor tree to check if the referred node is
* defined
@@ -465,6 +474,12 @@
}
potentialAncestorWithReferredNode = potentialAncestorWithReferredNode.getParent();
+
+ if (type != null && potentialAncestorWithReferredNode != null) {
+ if (potentialAncestorWithReferredNode.getParent() == null) {
+ type.setTypeNotResolvedTillRootNode(true);
+ }
+ }
}
}
@@ -719,7 +734,8 @@
* @throws DataModelException data model errors
*/
private YangNode isReferredNodeInSiblingProcessedForIdentity(YangNode potentialReferredNode,
- String referredNodeName) throws DataModelException {
+ String referredNodeName)
+ throws DataModelException {
while (potentialReferredNode != null) {
if (potentialReferredNode instanceof YangIdentity) {
@@ -902,7 +918,8 @@
return false;
}
- private boolean isFeatureDefinedInNode(YangNode node) throws DataModelException {
+ private boolean isFeatureDefinedInNode(YangNode node)
+ throws DataModelException {
YangNodeIdentifier ifFeature = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getName();
List<YangFeature> featureList = ((YangFeatureHolder) node).getFeatureList();
if (featureList != null && !featureList.isEmpty()) {
@@ -1209,7 +1226,7 @@
* @param root root node
*/
private void processXPathLinking(T entityToResolve,
- YangReferenceResolver root) {
+ YangReferenceResolver root) {
YangXpathLinker<T> xPathLinker = new YangXpathLinker<T>();
@@ -1455,7 +1472,8 @@
* @param resolutionInfo information about the YANG construct which has to be resolved
* @throws DataModelException a violation of data model rules
*/
- public void setAbsolutePathFromRelativePathInLeafref(T resolutionInfo) throws DataModelException {
+ public void setAbsolutePathFromRelativePathInLeafref(T resolutionInfo)
+ throws DataModelException {
if (resolutionInfo instanceof YangLeafRef) {
YangNode parentOfLeafref = ((YangLeafRef) resolutionInfo).getParentNodeOfLeafref();
@@ -1504,7 +1522,8 @@
* @throws DataModelException a violation of data model rules
*/
private void fillAbsolutePathValuesInLeafref(YangLeafRef leafref, String pathNameToBePrefixed,
- List<YangAtomicPath> atomicPathsInRelative) throws DataModelException {
+ List<YangAtomicPath> atomicPathsInRelative)
+ throws DataModelException {
leafref.setPathType(YangPathArgType.ABSOLUTE_PATH);
String[] pathName = new String[0];
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java
index 49037e2..2d04602 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java
@@ -33,11 +33,13 @@
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IDENTITYREF_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
+ .constructExtendedListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
+ .constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
@@ -71,7 +73,7 @@
* @param ctx context object of the grammar rule
*/
public static void processIdentityrefEntry(TreeWalkListener listener,
- GeneratedYangParser.IdentityrefSpecificationContext ctx) {
+ GeneratedYangParser.IdentityrefSpecificationContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, IDENTITYREF_DATA, "", ENTRY);
@@ -85,7 +87,7 @@
// Validate node identifier.
YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.baseStatement().string().getText(),
- BASE_DATA, ctx);
+ BASE_DATA, ctx);
identityRef.setBaseIdentity(nodeIdentifier);
((YangType) typeData).setDataTypeExtendedInfo(identityRef);
@@ -106,16 +108,17 @@
// Verify parent node of leaf
if (!(parentNodeOfLeaf instanceof YangNode)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- IDENTITYREF_DATA, ctx.getText(), EXIT));
+ IDENTITYREF_DATA, ctx.getText(), EXIT));
}
identityRef.setResolvableStatus(UNRESOLVED);
- // Add resolution information to the list
- resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
- (YangNode) parentNodeOfLeaf, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
-
+ if (listener.getGroupingDepth() == 0) {
+ // Add resolution information to the list
+ resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
+ (YangNode) parentNodeOfLeaf, errorLine, errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
+ }
break;
case LEAF_LIST_DATA:
@@ -129,15 +132,17 @@
// Verify parent node of leaf
if (!(parentNodeOfLeafList instanceof YangNode)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- IDENTITYREF_DATA, ctx.getText(), EXIT));
+ IDENTITYREF_DATA, ctx.getText(), EXIT));
}
identityRef.setResolvableStatus(UNRESOLVED);
- // Add resolution information to the list
- resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
- (YangNode) parentNodeOfLeafList, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
+ if (listener.getGroupingDepth() == 0) {
+ // Add resolution information to the list
+ resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
+ (YangNode) parentNodeOfLeafList, errorLine, errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
+ }
break;
case UNION_DATA:
@@ -146,16 +151,17 @@
// Verify parent node of leaf
if (!(parentNodeOfUnionNode instanceof YangNode)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- IDENTITYREF_DATA, ctx.getText(), EXIT));
+ IDENTITYREF_DATA, ctx.getText(), EXIT));
}
identityRef.setResolvableStatus(UNRESOLVED);
- // Add resolution information to the list
- resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
- (YangNode) parentNodeOfUnionNode, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
-
+ if (listener.getGroupingDepth() == 0) {
+ // Add resolution information to the list
+ resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
+ (YangNode) parentNodeOfUnionNode, errorLine, errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
+ }
break;
case TYPEDEF_DATA:
/**
@@ -167,11 +173,11 @@
break;
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
- ctx.getText(), EXIT));
+ ctx.getText(), EXIT));
}
listener.getParsedDataStack().push(typeData);
listener.getParsedDataStack().push(identityRef);
- } else {
+ } else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA, "", ENTRY));
}
}
@@ -184,7 +190,7 @@
* @param ctx context object of the grammar rule
*/
public static void processIdentityrefExit(TreeWalkListener listener,
- GeneratedYangParser.IdentityrefSpecificationContext ctx) {
+ GeneratedYangParser.IdentityrefSpecificationContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, IDENTITYREF_DATA, ctx.getText(), EXIT);
@@ -192,7 +198,7 @@
Parsable parsableType = listener.getParsedDataStack().pop();
if (!(parsableType instanceof YangIdentityRef)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
- ctx.getText(), EXIT));
+ ctx.getText(), EXIT));
}
}
@@ -203,12 +209,12 @@
* @param ctx context object of the grammar rule
*/
private static void addToResolutionList(YangResolutionInfoImpl<YangIdentityRef> resolutionInfo,
- GeneratedYangParser.IdentityrefSpecificationContext ctx) {
+ GeneratedYangParser.IdentityrefSpecificationContext ctx) {
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- IDENTITYREF_DATA, ctx.getText(), ENTRY, e.getMessage()));
+ IDENTITYREF_DATA, ctx.getText(), ENTRY, e.getMessage()));
}
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
index 972d1ef..c77ffea 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
@@ -17,6 +17,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.util.Date;
+
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
index 3c7fba9..73b62b2 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
@@ -38,8 +38,10 @@
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
+ .constructExtendedListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
+ .constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
@@ -82,7 +84,7 @@
* @param ctx context object of the grammar rule
*/
public static void processTypeEntry(TreeWalkListener listener,
- GeneratedYangParser.TypeStatementContext ctx) {
+ GeneratedYangParser.TypeStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), ENTRY);
@@ -136,10 +138,12 @@
type.setResolvableStatus(UNRESOLVED);
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangType>(type,
- (YangNode) parentNodeOfLeaf, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
+ if (listener.getGroupingDepth() == 0) {
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangType>(type,
+ (YangNode) parentNodeOfLeaf, errorLine, errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
+ }
}
break;
case LEAF_LIST_DATA:
@@ -166,11 +170,13 @@
YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangType>(type, (YangNode) parentNodeOfLeafList, errorLine,
- errorPosition);
- addToResolutionList(resolutionInfo, ctx);
+ if (listener.getGroupingDepth() == 0) {
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo =
+ new YangResolutionInfoImpl<YangType>(type, (YangNode) parentNodeOfLeafList, errorLine,
+ errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
+ }
}
break;
case UNION_DATA:
@@ -196,10 +202,12 @@
type.setResolvableStatus(UNRESOLVED);
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangType>(type, unionNode, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
+ if (listener.getGroupingDepth() == 0) {
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo =
+ new YangResolutionInfoImpl<YangType>(type, unionNode, errorLine, errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
+ }
}
break;
@@ -218,11 +226,12 @@
((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
type.setResolvableStatus(UNRESOLVED);
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangType>(type, typeDef, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
+ if (listener.getGroupingDepth() == 0) {
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo =
+ new YangResolutionInfoImpl<YangType>(type, typeDef, errorLine, errorPosition);
+ addToResolutionList(resolutionInfo, ctx);
+ }
}
break;
//TODO: deviate replacement statement.
@@ -256,7 +265,7 @@
* @param ctx context object of the grammar rule
*/
public static void processTypeExit(TreeWalkListener listener,
- GeneratedYangParser.TypeStatementContext ctx) {
+ GeneratedYangParser.TypeStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT);
@@ -275,7 +284,7 @@
* @param ctx context object of the grammar rule
*/
private static void addToResolutionList(YangResolutionInfoImpl<YangType> resolutionInfo,
- GeneratedYangParser.TypeStatementContext ctx) {
+ GeneratedYangParser.TypeStatementContext ctx) {
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
@@ -291,7 +300,7 @@
* @param yangDataType yang data type
*/
private static void validateTypeSubStatementCardinality(GeneratedYangParser.TypeStatementContext ctx,
- YangDataTypes yangDataType) {
+ YangDataTypes yangDataType) {
if (ctx.typeBodyStatements() == null || ctx.typeBodyStatements().isEmpty()) {
ParserException parserException;
switch (yangDataType) {
@@ -317,7 +326,7 @@
break;
case IDENTITYREF:
parserException = new ParserException("YANG file error : a type identityref" +
- " must have base statement.");
+ " must have base statement.");
break;
default:
return;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index af4deb9..9ffb424 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -32,6 +32,8 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.YangLinker;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
@@ -45,6 +47,9 @@
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
+import static org.onosproject.yangutils.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
+import static org.onosproject.yangutils.datamodel.ResolvableType.YANG_IDENTITYREF;
+import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.resolveGroupingInDefinationScope;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.copyYangFilesToTarget;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.resolveInterJarDependencies;
@@ -214,7 +219,6 @@
if (getCurYangFileInfo() != null) {
fileName = getCurYangFileInfo().getYangFileName();
}
-
try {
translatorErrorHandler(getRootNode(), yangPlugin);
deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG);
@@ -242,7 +246,8 @@
*
* @throws IOException when fails to do IO operations
*/
- private void resolveInterJarDependency() throws IOException {
+ private void resolveInterJarDependency()
+ throws IOException {
try {
List<YangNode> interJarResolvedNodes = resolveInterJarDependencies(project, localRepository,
remoteRepository, getDirectory(baseDir, outputDirectory));
@@ -298,6 +303,13 @@
YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName());
yangFileInfo.setRootNode(yangNode);
setRootNode(yangNode);
+ resolveGroupingInDefinationScope((YangReferenceResolver) yangNode);
+ try {
+ ((YangReferenceResolver) yangNode).resolveSelfFileLinking(YANG_DERIVED_DATA_TYPE);
+ ((YangReferenceResolver) yangNode).resolveSelfFileLinking(YANG_IDENTITYREF);
+ } catch (DataModelException e) {
+ //TODO: throw exception : throw e;
+ }
} catch (ParserException e) {
String logInfo = "Error in file: " + e.getFileName();
if (e.getLineNumber() != 0) {