[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/impl/Resolvable.java
deleted file mode 100644
index f384dc5..0000000
--- a/src/main/java/org/onosproject/yangutils/linker/impl/Resolvable.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.impl;
-
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
-
-/**
- * Abstraction of YANG resolvable information. Abstracted to obtain the
- * information required for linking resolution.
- */
-public interface Resolvable {
-
- /**
- * Returns the status of resolution. If completely resolved returns enum
- * value "RESOLVED", if not returns "UNRESOLVED", in case reference of
- * grouping/typedef is added to uses/type but it's not resolved
- * "INTRA_FILE_RESOLVED" is returned.
- *
- * @return status of resolution
- */
- ResolvableStatus getResolvableStatus();
-
- /**
- * Set the status of type/uses resolution. If completely resolved set enum
- * value "RESOLVED", if not set it to "UNRESOLVED", in case reference of
- * grouping/typedef is added to uses/type but it's not resolved
- * "INTRA_FILE_RESOLVED" should be set.
- *
- * @param resolvableStatus status of resolution
- */
- void setResolvableStatus(ResolvableStatus resolvableStatus);
-
- /**
- * Resolves the linking.
- *
- * @throws LinkerException linker error
- */
- void resolve()
- throws LinkerException;
-}
diff --git a/src/main/java/org/onosproject/yangutils/linker/impl/ResolvableStatus.java b/src/main/java/org/onosproject/yangutils/linker/impl/ResolvableStatus.java
deleted file mode 100644
index cd43c18..0000000
--- a/src/main/java/org/onosproject/yangutils/linker/impl/ResolvableStatus.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.impl;
-
-/**
- * Represents the status of resolvable entity.
- */
-public enum ResolvableStatus {
-
- /**
- * Identifies that resolvable entity is unresolved.
- */
- UNRESOLVED,
-
- /**
- * Identifies that resolvable entity's reference is linked.
- */
- LINKED,
-
- /**
- * Identifies that resolvable entity is IntraFile resolved (i.e. complete
- * linking with in the intra file).
- */
- INTRA_FILE_RESOLVED,
-
- /**
- * Identifies that resolvable entity is resolved.
- */
- RESOLVED,
-
- /**
- * Identifies that resolvable entity is inter file linked (i.e. complete
- * linking with external files).
- */
- INTER_FILE_LINKED
-
-}
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/YangReferenceResolver.java b/src/main/java/org/onosproject/yangutils/linker/impl/YangReferenceResolver.java
deleted file mode 100644
index 4681985..0000000
--- a/src/main/java/org/onosproject/yangutils/linker/impl/YangReferenceResolver.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.impl;
-
-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.plugin.manager.YangFileInfo;
-
-/**
- * Abstraction of YANG dependency resolution information. Abstracted to obtain the
- * resolution information.
- */
-public interface YangReferenceResolver {
-
- /**
- * Returns unresolved resolution list.
- *
- * @return unresolved resolution list
- */
- List<YangResolutionInfo> getUnresolvedResolutionList();
-
- /**
- * Adds to the resolution list.
- *
- * @param resolutionInfo resolution information
- */
- void addToResolutionList(YangResolutionInfo resolutionInfo);
-
- /**
- * Creates resolution list.
- *
- * @param resolutionList resolution list
- */
- void setResolutionList(List<YangResolutionInfo> resolutionList);
-
- /**
- * Returns unresolved imported list.
- *
- * @return unresolved imported list
- */
- List<YangImport> getImportList();
-
- /**
- * Adds to the import list.
- *
- * @param yangImport import to be added
- */
- void addToImportList(YangImport yangImport);
-
- /**
- * Create import list.
- *
- * @param importList import list
- */
- void setImportList(List<YangImport> importList);
-
- /**
- * Returns unresolved include list.
- *
- * @return unresolved include list
- */
- List<YangInclude> getIncludeList();
-
- /**
- * Adds to the include list.
- *
- * @param yangInclude include to be added
- */
- void addToIncludeList(YangInclude yangInclude);
-
- /**
- * Creates include list.
- *
- * @param includeList include list
- */
- void setIncludeList(List<YangInclude> includeList);
-
- /**
- * Returns prefix of resolution root node.
- *
- * @return prefix resolution root node prefix
- */
- String getPrefix();
-
- /**
- * Sets prefix of resolution list root node.
- *
- * @param prefix resolution root node prefix
- */
- void setPrefix(String prefix);
-
- /**
- * Resolves self file linking.
- *
- * @throws DataModelException a violation in data model rule
- */
- void resolveSelfFileLinking() throws DataModelException;
-
- /**
- * Resolves inter file linking.
- *
- * @throws DataModelException a violation in data model rule
- */
- void resolveInterFileLinking() throws DataModelException;
-
- /**
- * Adds references to include.
- *
- * @param yangFileInfoSet YANG file info set
- * @throws LinkerException a violation of linker rules
- */
- void addReferencesToIncludeList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException;
-
- /**
- * Adds references to import.
- *
- * @param yangFileInfoSet YANG file info set
- * @throws LinkerException a violation of linker rules
- */
- void addReferencesToImportList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException;
-}
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();