[ONOS-4941][ONOS-4883][ONOS-4979]Grouping and uses interfile linking issue + defect fix
Change-Id: I5e8145f05d3ef570d4ecbbe885c93de172de0ea3
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppDataStructure.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppDataStructure.java
new file mode 100644
index 0000000..80ea6c6
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppDataStructure.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/**
+ * Represents data model node to maintain information defined in YANG app-data-structure.
+ */
+public class YangAppDataStructure implements Parsable {
+
+ /**
+ * Data structure information.
+ */
+ private YangDataStructure dataStructure;
+
+ /**
+ * List of key names.
+ */
+ private List<String> keyList;
+
+ /**
+ * Prefix of app-data-structure.
+ */
+ private String prefix;
+
+ /**
+ * Returns the YANG data structure information.
+ *
+ * @return the YANG data structure information
+ */
+ public YangDataStructure getDataStructure() {
+ return dataStructure;
+ }
+
+ /**
+ * Sets the YANG data structure information.
+ *
+ * @param dataStructure the YANG data structure to set
+ */
+ public void setDataStructure(YangDataStructure dataStructure) {
+ this.dataStructure = dataStructure;
+ }
+
+ /**
+ * Returns the list of key field names.
+ *
+ * @return the list of key field names
+ */
+ public List<String> getKeyList() {
+ return keyList;
+ }
+
+ /**
+ * Sets the list of key field names.
+ *
+ * @param keyList the list of key field names
+ */
+ public void setKeyList(List<String> keyList) {
+ this.keyList = keyList;
+ }
+
+ /**
+ * Adds a key field name.
+ *
+ * @param key key field name
+ */
+ public void addKey(String key) {
+ if (getKeyList() == null) {
+ setKeyList(new LinkedList<>());
+ }
+ getKeyList().add(key);
+ }
+
+ /**
+ * Returns the prefix.
+ *
+ * @return the prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Sets the prefix information.
+ *
+ * @param prefix the prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.APP_DATA_STRUCTURE;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO : to be implemented
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO : to be implemented
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppExtendedName.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppExtendedName.java
new file mode 100644
index 0000000..2ab743e
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppExtendedName.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/**
+ * Represents data model node to maintain information defined in YANG extended name.
+ */
+public class YangAppExtendedName implements Parsable {
+
+ /**
+ * App extended name information.
+ */
+ private String yangAppExtendedName;
+
+ /**
+ * Prefix of extended name.
+ */
+ private String prefix;
+
+ /**
+ * Returns the YANG app extended name information.
+ *
+ * @return the YANG app extended name information
+ */
+ public String getYangAppExtendedName() {
+ return yangAppExtendedName;
+ }
+
+ /**
+ * Sets the YANG app extended name information.
+ *
+ * @param yangAppExtendedName the YANG app extended name to set
+ */
+ public void setYangAppExtendedName(String yangAppExtendedName) {
+ this.yangAppExtendedName = yangAppExtendedName;
+ }
+
+ /**
+ * Returns the prefix.
+ *
+ * @return the prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Sets the prefix information.
+ *
+ * @param prefix the prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.APP_EXTENDED_NAME_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO : to be implemented
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO : to be implemented
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCompilerAnnotation.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCompilerAnnotation.java
new file mode 100644
index 0000000..4d0c2ce
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCompilerAnnotation.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+
+/**
+ * Represents data model node to maintain information defined in YANG compiler-annotation.
+ */
+public class YangCompilerAnnotation implements Parsable {
+
+ /**
+ * App data structure information.
+ */
+ private YangAppDataStructure yangAppDataStructure;
+
+ /**
+ * App extended name information.
+ */
+ private YangAppExtendedName yangAppExtendedName;
+
+ /**
+ * Prefix of compiler-annotation.
+ */
+ private String prefix;
+
+ /**
+ * Path of compiler-annotation.
+ */
+ private String path;
+
+ /**
+ * Returns the YANG app data structure information.
+ *
+ * @return the YANG app data structure information
+ */
+ public YangAppDataStructure getYangAppDataStructure() {
+ return yangAppDataStructure;
+ }
+
+ /**
+ * Sets the YANG app data structure information.
+ *
+ * @param yangAppDataStructure the YANG app data structure to set
+ */
+ public void setYangAppDataStructure(YangAppDataStructure yangAppDataStructure) {
+ this.yangAppDataStructure = yangAppDataStructure;
+ }
+
+ /**
+ * Returns the prefix.
+ *
+ * @return the prefix
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
+ * Sets the prefix information.
+ *
+ * @param prefix the prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ /**
+ * Returns the path.
+ *
+ * @return the path
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * Sets the path.
+ *
+ * @param path the path to set
+ */
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ /**
+ * Returns the YANG app extended name information.
+ *
+ * @return the YANG app extended name information
+ */
+ public YangAppExtendedName getYangAppExtendedName() {
+ return yangAppExtendedName;
+ }
+
+ /**
+ * Sets the YANG app extended name information.
+ *
+ * @param yangAppExtendedName the YANG app extended name to set
+ */
+ public void setYangAppExtendedName(YangAppExtendedName yangAppExtendedName) {
+ this.yangAppExtendedName = yangAppExtendedName;
+ }
+
+ @Override
+ public YangConstructType getYangConstructType() {
+ return YangConstructType.COMPILER_ANNOTATION_DATA;
+ }
+
+ @Override
+ public void validateDataOnEntry() throws DataModelException {
+ // TODO : to be implemented
+ }
+
+ @Override
+ public void validateDataOnExit() throws DataModelException {
+ // TODO : to be implemented
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataStructure.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataStructure.java
new file mode 100644
index 0000000..785d460
--- /dev/null
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataStructure.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Represents ENUM to identify the YANG data type.
+ */
+public enum YangDataStructure {
+
+ MAP,
+
+ LIST,
+
+ SET;
+
+ /**
+ * Returns YANG data structure type for corresponding data structure name.
+ *
+ * @param name data structure name from YANG file.
+ * @return YANG data structure for corresponding data structure name.
+ */
+ public static YangDataStructure getType(String name) {
+ name = name.replace("\"", "");
+ for (YangDataStructure dataStructure : values()) {
+ if (dataStructure.name().toLowerCase().equals(name)) {
+ return dataStructure;
+ }
+ }
+ return null;
+ }
+}
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
index 2b2426a..b86911a 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
@@ -16,15 +16,14 @@
package org.onosproject.yangutils.datamodel;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
/*
@@ -72,7 +71,7 @@
public class YangList
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
- YangAugmentableNode, YangMustHolder, YangIfFeatureHolder, YangDataNode {
+ YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangDataNode {
private static final long serialVersionUID = 806201609L;
@@ -219,6 +218,7 @@
*
* @return the when
*/
+ @Override
public YangWhen getWhen() {
return when;
}
@@ -228,6 +228,7 @@
*
* @param when the when to set
*/
+ @Override
public void setWhen(YangWhen when) {
this.when = when;
}
@@ -624,7 +625,6 @@
* Validates key statement of list.
*
* @param leaves list of leaf attributes of list
- * @param leafLists list of leaf-list attributes of list
* @param keys list of key attributes of list
* @throws DataModelException a violation of data model rules
*/
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
index f9b1e87..8e5de36 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
@@ -231,7 +231,12 @@
private List<YangResolutionInfo> augmentResolutionList;
/**
- * extension list.
+ * Compiler annotation list.
+ */
+ private List<YangCompilerAnnotation> compilerAnnotationList;
+
+ /**
+ * Extension list.
*/
private List<YangExtension> extensionList;
@@ -248,6 +253,7 @@
leafrefResolutionList = new LinkedList<>();
baseResolutionList = new LinkedList<>();
identityrefResolutionList = new LinkedList<>();
+ compilerAnnotationList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
@@ -563,6 +569,33 @@
}
/**
+ * Adds compiler annotation in compiler-annotation list.
+ *
+ * @param compilerAnnotation the compiler-annotation to be added
+ */
+ public void addCompilerAnnotation(YangCompilerAnnotation compilerAnnotation) {
+ getCompilerAnnotationList().add(compilerAnnotation);
+ }
+
+ /**
+ * Returns the compiler annotation list.
+ *
+ * @return the compiler annotation list
+ */
+ public List<YangCompilerAnnotation> getCompilerAnnotationList() {
+ return compilerAnnotationList;
+ }
+
+ /**
+ * Sets the compiler-annotation list.
+ *
+ * @param compilerAnnotationList the list of compiler-annotation
+ */
+ public void setCompilerAnnotationList(List<YangCompilerAnnotation> compilerAnnotationList) {
+ this.compilerAnnotationList = compilerAnnotationList;
+ }
+
+ /**
* Adds extension in extension list.
*
* @param extension the extension to be added
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
index f8bec7c..800e062 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
@@ -224,6 +224,11 @@
private List<YangResolutionInfo> identityrefResolutionList;
/**
+ * Compiler annotation list.
+ */
+ private List<YangCompilerAnnotation> compilerAnnotationList;
+
+ /**
* extension list.
*/
private List<YangExtension> extensionList;
@@ -245,6 +250,7 @@
leafrefResolutionList = new LinkedList<>();
baseResolutionList = new LinkedList<>();
identityrefResolutionList = new LinkedList<>();
+ compilerAnnotationList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
@@ -692,6 +698,34 @@
}
/**
+ * Adds compiler annotation in compiler annotation list.
+ *
+ * @param compilerAnnotation the compiler annotation to be added
+ */
+ public void addCompilerAnnotation(YangCompilerAnnotation compilerAnnotation) {
+ getCompilerAnnotationList().add(compilerAnnotation);
+ }
+
+ /**
+ * Returns the compiler annotation list.
+ *
+ * @return the compiler annotation list
+ */
+ public List<YangCompilerAnnotation> getCompilerAnnotationList() {
+ return compilerAnnotationList;
+ }
+
+ /**
+ * Sets the compiler annotation list.
+ *
+ * @param compilerAnnotationList the list of compiler annotation
+ */
+ public void setCompilerAnnotationList(List<YangCompilerAnnotation> compilerAnnotationList) {
+ this.compilerAnnotationList = compilerAnnotationList;
+ }
+
+
+ /**
* Adds extension in extension list.
*
* @param extension the extension to be added
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
index 5cd1e7a..6b76dfd 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangUses.java
@@ -17,17 +17,20 @@
import java.util.LinkedList;
import java.util.List;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+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.detectCollidingChildUtil;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClonedLeavesUnionEnumRef;
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.updateClonedLeavesUnionEnumRef;
/*-
* Reference RFC 6020.
@@ -365,6 +368,14 @@
if (referredGrouping == null) {
throw new DataModelException("YANG uses linker error, cannot resolve uses");
+ } else {
+ /*
+ * if referredGrouping has uses which is not resolved then set the status
+ * as Intra file resolved and return
+ */
+ if (checkIsUnresolvedRecursiveUsesInGrouping(referredGrouping)) {
+ return null;
+ }
}
YangNode usesParentNode = getParentNodeInGenCode(this);
@@ -405,7 +416,7 @@
clonedLeafList = leafList.clone();
if (getCurrentGroupingDepth() == 0) {
YangEntityToResolveInfoImpl resolveInfo =
- resolveLeafrefUnderGroupingForLeafList(clonedLeafList, usesParentLeavesHolder);
+ resolveLeafrefUnderGroupingForLeafList(clonedLeafList, usesParentLeavesHolder);
if (resolveInfo != null) {
addEntityToResolve(resolveInfo);
}
@@ -429,6 +440,49 @@
}
/**
+ * Checks if referred grouping has uses which is not resolved then it set the
+ * status of current uses as intra file resolved and returns true.
+ *
+ * @param referredGrouping referred grouping node of uses
+ * @return true if referred grouping has unresolved uses
+ */
+ private boolean checkIsUnresolvedRecursiveUsesInGrouping(YangGrouping referredGrouping) {
+
+ /**
+ * Search the grouping node's children for presence of uses node.
+ */
+ TraversalType curTraversal = ROOT;
+ YangNode curNode = referredGrouping.getChild();
+ while (curNode != null) {
+ if (curNode.getName().equals(referredGrouping.getName())) {
+ // if we have traversed all the child nodes, then exit from loop
+ return false;
+ }
+
+ // if child nodes has uses, then add it to resolution stack
+ if (curNode instanceof YangUses) {
+ if (((YangUses) curNode).getResolvableStatus() != ResolvableStatus.RESOLVED) {
+ setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
+ return true;
+ }
+ }
+
+ // Traversing all the child nodes of grouping
+ 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();
+ }
+ }
+ return false;
+ }
+
+ /**
* Clone the resolved uses contained in grouping to the uses of grouping.
*
* @param usesInGrouping resolved uses in grouping
diff --git a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/YangConstructType.java b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/YangConstructType.java
index e0dd8e3..fc0fbd7 100644
--- a/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/YangConstructType.java
+++ b/utils/yangutils/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/YangConstructType.java
@@ -385,6 +385,21 @@
ANYXML_DATA,
/**
+ * Identifies the YANG compiler annotation element parsed data.
+ */
+ COMPILER_ANNOTATION_DATA,
+
+ /**
+ * Identifies the YANG app data structure element parsed data.
+ */
+ APP_DATA_STRUCTURE,
+
+ /**
+ * Identifies the YANG app extended element parsed data.
+ */
+ APP_EXTENDED_NAME_DATA,
+
+ /**
* Identifies the YANG argument element parsed data.
*/
ARGUMENT_DATA;
@@ -544,6 +559,12 @@
return "deviation";
case ANYXML_DATA:
return "anyxml";
+ case COMPILER_ANNOTATION_DATA:
+ return "compiler-annotation";
+ case APP_DATA_STRUCTURE:
+ return "app-data-structure";
+ case APP_EXTENDED_NAME_DATA:
+ return "app-extended-name";
case ARGUMENT_DATA:
return "argument";
default: