[ONOS-4636]YANG Grouping linking bug fix + YANG Code review comment fix
Change-Id: I68ee8dd08266a02593e217cef1a9bb010037d673
diff --git a/src/main/java/org/onosproject/yangutils/linker/impl/Resolvable.java b/src/main/java/org/onosproject/yangutils/linker/Resolvable.java
similarity index 97%
rename from src/main/java/org/onosproject/yangutils/linker/impl/Resolvable.java
rename to src/main/java/org/onosproject/yangutils/linker/Resolvable.java
index f384dc5..975c3f4 100644
--- a/src/main/java/org/onosproject/yangutils/linker/impl/Resolvable.java
+++ b/src/main/java/org/onosproject/yangutils/linker/Resolvable.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.linker.impl;
+package org.onosproject.yangutils.linker;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
diff --git a/src/main/java/org/onosproject/yangutils/linker/impl/ResolvableStatus.java b/src/main/java/org/onosproject/yangutils/linker/ResolvableStatus.java
similarity index 96%
rename from src/main/java/org/onosproject/yangutils/linker/impl/ResolvableStatus.java
rename to src/main/java/org/onosproject/yangutils/linker/ResolvableStatus.java
index cd43c18..0ff5da5 100644
--- a/src/main/java/org/onosproject/yangutils/linker/impl/ResolvableStatus.java
+++ b/src/main/java/org/onosproject/yangutils/linker/ResolvableStatus.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.linker.impl;
+package org.onosproject.yangutils.linker;
/**
* Represents the status of resolvable entity.
diff --git a/src/main/java/org/onosproject/yangutils/linker/ResolvableType.java b/src/main/java/org/onosproject/yangutils/linker/ResolvableType.java
new file mode 100644
index 0000000..ff0778f
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/linker/ResolvableType.java
@@ -0,0 +1,33 @@
+/*
+ * 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.linker;
+
+/**
+ * Type of the resolvable info.
+ */
+public enum ResolvableType {
+
+ /**
+ * Identifies the derived data type.
+ */
+ YANG_DERIVED_DATA_TYPE,
+
+ /**
+ * Identifies the uses.
+ */
+ YANG_USES
+}
diff --git a/src/main/java/org/onosproject/yangutils/linker/YangLinkingPhase.java b/src/main/java/org/onosproject/yangutils/linker/YangLinkingPhase.java
new file mode 100644
index 0000000..23020df
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/linker/YangLinkingPhase.java
@@ -0,0 +1,34 @@
+/*
+ * 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.linker;
+
+/**
+ * Represents the phase of YANG file reference linking.
+ */
+public enum YangLinkingPhase {
+
+ /**
+ * Linking the reference within the files.
+ */
+ INTRA_FILE,
+
+ /**
+ * Linking the reference across the files.
+ */
+ INTER_FILE
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/linker/impl/YangReferenceResolver.java b/src/main/java/org/onosproject/yangutils/linker/YangReferenceResolver.java
similarity index 80%
rename from src/main/java/org/onosproject/yangutils/linker/impl/YangReferenceResolver.java
rename to src/main/java/org/onosproject/yangutils/linker/YangReferenceResolver.java
index 4681985..307675d 100644
--- a/src/main/java/org/onosproject/yangutils/linker/impl/YangReferenceResolver.java
+++ b/src/main/java/org/onosproject/yangutils/linker/YangReferenceResolver.java
@@ -14,14 +14,16 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.linker.impl;
+package org.onosproject.yangutils.linker;
import java.util.List;
import java.util.Set;
+
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
/**
@@ -33,23 +35,26 @@
/**
* Returns unresolved resolution list.
*
- * @return unresolved resolution list
+ * @param type resolvable type
+ * @return list of resolution information objects
*/
- List<YangResolutionInfo> getUnresolvedResolutionList();
+ List<YangResolutionInfo> getUnresolvedResolutionList(ResolvableType type);
/**
* Adds to the resolution list.
*
* @param resolutionInfo resolution information
+ * @param type resolvable type
*/
- void addToResolutionList(YangResolutionInfo resolutionInfo);
+ void addToResolutionList(YangResolutionInfo resolutionInfo, ResolvableType type);
/**
* Creates resolution list.
*
* @param resolutionList resolution list
+ * @param type resolvable type
*/
- void setResolutionList(List<YangResolutionInfo> resolutionList);
+ void setResolutionList(List<YangResolutionInfo> resolutionList, ResolvableType type);
/**
* Returns unresolved imported list.
@@ -110,16 +115,20 @@
/**
* Resolves self file linking.
*
+ * @param type resolvable type
* @throws DataModelException a violation in data model rule
*/
- void resolveSelfFileLinking() throws DataModelException;
+ void resolveSelfFileLinking(ResolvableType type)
+ throws DataModelException;
/**
* Resolves inter file linking.
*
+ * @param type resolvable type
* @throws DataModelException a violation in data model rule
*/
- void resolveInterFileLinking() throws DataModelException;
+ void resolveInterFileLinking(ResolvableType type)
+ throws DataModelException;
/**
* Adds references to include.
@@ -127,7 +136,8 @@
* @param yangFileInfoSet YANG file info set
* @throws LinkerException a violation of linker rules
*/
- void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException;
+ void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet)
+ throws LinkerException;
/**
* Adds references to import.
@@ -135,5 +145,6 @@
* @param yangFileInfoSet YANG file info set
* @throws LinkerException a violation of linker rules
*/
- void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException;
+ void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet)
+ throws LinkerException;
}
diff --git a/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
index 0fc3d99..deaebb2 100644
--- a/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
+++ b/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
@@ -17,10 +17,13 @@
package org.onosproject.yangutils.linker.impl;
import java.util.Set;
+
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.ResolvableType;
import org.onosproject.yangutils.linker.YangLinker;
+import org.onosproject.yangutils.linker.YangReferenceResolver;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
@@ -29,7 +32,8 @@
/**
* Representation of entity which provides linking service of YANG files.
*/
-public class YangLinkerManager implements YangLinker {
+public class YangLinkerManager
+ implements YangLinker {
@Override
public void resolveDependencies(Set<YangFileInfo> yangFileInfoSet) {
@@ -54,7 +58,8 @@
* @param yangFileInfoSet set of YANG files info
* @throws LinkerException fails to link sub-module to parent module
*/
- public void linkSubModulesToParentModule(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
+ public void linkSubModulesToParentModule(Set<YangFileInfo> yangFileInfoSet)
+ throws LinkerException {
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
YangNode yangNode = yangFileInfo.getRootNode();
if (yangNode instanceof YangSubModule) {
@@ -106,10 +111,13 @@
* @param yangFileInfoSet set of YANG files info
* @throws LinkerException a violation in linker execution
*/
- public void processInterFileLinking(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
+ public void processInterFileLinking(Set<YangFileInfo> yangFileInfoSet)
+ throws LinkerException {
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
try {
- ((YangReferenceResolver) yangFileInfo.getRootNode()).resolveInterFileLinking();
+ ((YangReferenceResolver) yangFileInfo.getRootNode()).resolveInterFileLinking(ResolvableType.YANG_USES);
+ ((YangReferenceResolver) yangFileInfo.getRootNode())
+ .resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
} catch (DataModelException e) {
String errorInfo = "Error in file: " + yangFileInfo.getYangFileName() + " at line: "
+ e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
diff --git a/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java b/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java
index 26d4cb6..83b11c4 100644
--- a/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java
+++ b/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfo.java
@@ -17,6 +17,7 @@
package org.onosproject.yangutils.linker.impl;
import java.util.Stack;
+
import org.onosproject.yangutils.datamodel.LocationInfo;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
@@ -28,12 +29,18 @@
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.Resolvable;
+import org.onosproject.yangutils.linker.ResolvableStatus;
+import org.onosproject.yangutils.linker.YangLinkingPhase;
+import org.onosproject.yangutils.linker.YangReferenceResolver;
-import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTER_FILE_LINKED;
-import static org.onosproject.yangutils.linker.impl.ResolvableStatus.INTRA_FILE_RESOLVED;
-import static org.onosproject.yangutils.linker.impl.ResolvableStatus.LINKED;
-import static org.onosproject.yangutils.linker.impl.ResolvableStatus.RESOLVED;
-import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED;
+import static org.onosproject.yangutils.linker.ResolvableStatus.INTER_FILE_LINKED;
+import static org.onosproject.yangutils.linker.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yangutils.linker.ResolvableStatus.LINKED;
+import static org.onosproject.yangutils.linker.ResolvableStatus.RESOLVED;
+import static org.onosproject.yangutils.linker.ResolvableStatus.UNRESOLVED;
+import static org.onosproject.yangutils.linker.YangLinkingPhase.INTER_FILE;
+import static org.onosproject.yangutils.linker.YangLinkingPhase.INTRA_FILE;
import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
@@ -42,7 +49,8 @@
*
* @param <T> type of resolution entity uses / type
*/
-public class YangResolutionInfo<T> implements LocationInfo {
+public class YangResolutionInfo<T>
+ implements LocationInfo {
/**
* Information about the entity that needs to be resolved.
@@ -164,7 +172,7 @@
* resolve the references and pop the entity and
* continue with remaining stack elements to resolve.
*/
- resolveTopOfStack();
+ resolveTopOfStack(INTRA_FILE);
getPartialResolvedStack().pop();
break;
}
@@ -213,7 +221,7 @@
/**
* Resolves the current entity in the stack.
*/
- private void resolveTopOfStack()
+ private void resolveTopOfStack(YangLinkingPhase linkingPhase)
throws DataModelException {
((Resolvable) getCurrentEntityToResolveFromStack()).resolve();
if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus()
@@ -280,7 +288,8 @@
* @return true if self file reference, false otherwise
* @throws DataModelException a violation of data model rules
*/
- private boolean isCandidateForSelfFileReference() throws DataModelException {
+ private boolean isCandidateForSelfFileReference()
+ throws DataModelException {
String prefix = getRefPrefix();
return prefix == null || prefix.contentEquals(getCurReferenceResolver().getPrefix());
}
@@ -598,7 +607,8 @@
* @return referenced prefix of entity under resolution
* @throws DataModelException a violation in data model rule
*/
- private String getRefPrefix() throws DataModelException {
+ private String getRefPrefix()
+ throws DataModelException {
String refPrefix;
if (getCurrentEntityToResolveFromStack() instanceof YangType) {
refPrefix = ((YangType<?>) getCurrentEntityToResolveFromStack()).getPrefix();
@@ -643,7 +653,7 @@
* resolve the references and pop the entity and
* continue with remaining stack elements to resolve
*/
- resolveTopOfStack();
+ resolveTopOfStack(INTER_FILE);
getPartialResolvedStack().pop();
break;
}
@@ -679,7 +689,8 @@
*
* @throws DataModelException data model error
*/
- private void linkInterFileTopOfStackRefUpdateStack() throws DataModelException {
+ private void linkInterFileTopOfStackRefUpdateStack()
+ throws DataModelException {
/*
* Obtain the referred node of top of stack entity under resolution
@@ -727,7 +738,8 @@
* @return true if resolved, false otherwise
* @throws DataModelException a violation in data model rule
*/
- private boolean resolveWithInclude() throws DataModelException {
+ private boolean resolveWithInclude()
+ throws DataModelException {
/*
* Run through all the nodes in include list and search for referred
* typedef/grouping at the root level.
@@ -762,7 +774,8 @@
* @return true if resolved, false otherwise
* @throws DataModelException a violation in data model rule
*/
- private boolean resolveWithImport() throws DataModelException {
+ private boolean resolveWithImport()
+ throws DataModelException {
/*
* Run through import list to find the referred typedef/grouping.
*/
@@ -808,7 +821,8 @@
* @return referred typedef/grouping node
* @throws DataModelException a violation in data model rule
*/
- private T getRefNode() throws DataModelException {
+ private T getRefNode()
+ throws DataModelException {
if (getCurrentEntityToResolveFromStack() instanceof YangType) {
YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>)
((YangType<?>) getCurrentEntityToResolveFromStack()).getDataTypeExtendedInfo();