[ONOS-4350] Inter file linking implementation and inter-jar linking framework

Change-Id: I71a26ba3e0b9d17261e78a9313fe7f047195932e
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
index ff25f00..08de56b 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
@@ -74,20 +74,26 @@
      * (belongsto), perform validations and update the data model tree.
      *
      * @param listener Listener's object
-     * @param ctx context object of the grammar rule
+     * @param ctx      context object of the grammar rule
      */
     public static void processBelongsToEntry(TreeWalkListener listener,
                                              GeneratedYangParser.BelongstoStatementContext ctx) {
 
         // Check for stack to be non empty.
         checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(),
-                             ENTRY);
+                ENTRY);
 
         String identifier = getValidIdentifier(ctx.identifier().getText(), BELONGS_TO_DATA, ctx);
 
         YangBelongsTo belongstoNode = new YangBelongsTo();
         belongstoNode.setBelongsToModuleName(identifier);
 
+        // Set the line number and character position in line for the belongs to.
+        int errorLine = ctx.getStart().getLine();
+        int errorPosition = ctx.getStart().getCharPositionInLine();
+        belongstoNode.setLineNumber(errorLine);
+        belongstoNode.setCharPosition(errorPosition);
+
         // Push belongsto into the stack.
         listener.getParsedDataStack().push(belongstoNode);
     }
@@ -97,14 +103,14 @@
      * validations and update the data model tree.
      *
      * @param listener Listener's object
-     * @param ctx context object of the grammar rule
+     * @param ctx      context object of the grammar rule
      */
     public static void processBelongsToExit(TreeWalkListener listener,
                                             GeneratedYangParser.BelongstoStatementContext ctx) {
 
         // Check for stack to be non empty.
         checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(),
-                             EXIT);
+                EXIT);
 
         Parsable tmpBelongstoNode = listener.getParsedDataStack().peek();
         if (tmpBelongstoNode instanceof YangBelongsTo) {
@@ -112,7 +118,7 @@
 
             // Check for stack to be empty.
             checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA,
-                                 ctx.identifier().getText(), EXIT);
+                    ctx.identifier().getText(), EXIT);
 
             Parsable tmpNode = listener.getParsedDataStack().peek();
             switch (tmpNode.getYangConstructType()) {
@@ -129,7 +135,7 @@
             }
         } else {
             throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BELONGS_TO_DATA,
-                                                                    ctx.identifier().getText(), EXIT));
+                    ctx.identifier().getText(), EXIT));
         }
     }
 }
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java
index 03938b1..061c4dd 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java
@@ -73,7 +73,7 @@
      * (import), perform validations and update the data model tree.
      *
      * @param listener Listener's object
-     * @param ctx context object of the grammar rule
+     * @param ctx      context object of the grammar rule
      */
     public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
 
@@ -85,6 +85,12 @@
         YangImport importNode = new YangImport();
         importNode.setModuleName(identifier);
 
+        // Set the line number and character position in line for the belongs to.
+        int errorLine = ctx.getStart().getLine();
+        int errorPosition = ctx.getStart().getCharPositionInLine();
+        importNode.setLineNumber(errorLine);
+        importNode.setCharPosition(errorPosition);
+
         // Push import node to the stack.
         listener.getParsedDataStack().push(importNode);
     }
@@ -94,7 +100,7 @@
      * validations and update the data model tree.
      *
      * @param listener Listener's object
-     * @param ctx context object of the grammar rule
+     * @param ctx      context object of the grammar rule
      */
     public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
 
@@ -107,7 +113,7 @@
 
             // Check for stack to be non empty.
             checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.identifier().getText(),
-                                 EXIT);
+                    EXIT);
 
             Parsable tmpNode = listener.getParsedDataStack().peek();
             switch (tmpNode.getYangConstructType()) {
@@ -128,7 +134,7 @@
             }
         } else {
             throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, IMPORT_DATA,
-                                                                    ctx.identifier().getText(), EXIT));
+                    ctx.identifier().getText(), EXIT));
         }
     }
 }
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java
index 721b9fe..8cac71d 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java
@@ -72,19 +72,25 @@
      * (include), perform validations and update the data model tree.
      *
      * @param listener Listener's object
-     * @param ctx context object of the grammar rule
+     * @param ctx      context object of the grammar rule
      */
     public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
 
         // Check for stack to be non empty.
         checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(),
-                             ENTRY);
+                ENTRY);
 
         String identifier = getValidIdentifier(ctx.identifier().getText(), INCLUDE_DATA, ctx);
 
         YangInclude includeNode = new YangInclude();
         includeNode.setSubModuleName(identifier);
 
+        // Set the line number and character position in line for the belongs to.
+        int errorLine = ctx.getStart().getLine();
+        int errorPosition = ctx.getStart().getCharPositionInLine();
+        includeNode.setLineNumber(errorLine);
+        includeNode.setCharPosition(errorPosition);
+
         listener.getParsedDataStack().push(includeNode);
     }
 
@@ -93,7 +99,7 @@
      * validations and update the data model tree.
      *
      * @param listener Listener's object
-     * @param ctx context object of the grammar rule
+     * @param ctx      context object of the grammar rule
      */
     public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
 
@@ -106,7 +112,7 @@
 
             // Check for stack to be non empty.
             checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(),
-                                 EXIT);
+                    EXIT);
 
             Parsable tmpNode = listener.getParsedDataStack().peek();
             switch (tmpNode.getYangConstructType()) {
@@ -127,7 +133,7 @@
             }
         } else {
             throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INCLUDE_DATA,
-                                                                    ctx.identifier().getText(), EXIT));
+                    ctx.identifier().getText(), EXIT));
         }
     }
 }
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
index 2f1d7fe..c78aa1e 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
@@ -16,7 +16,6 @@
 
 package org.onosproject.yangutils.parser.impl.listeners;
 
-import org.onosproject.yangutils.datamodel.YangDataTypes;
 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
 import org.onosproject.yangutils.datamodel.YangRangeRestriction;
 import org.onosproject.yangutils.datamodel.YangStringRestriction;
@@ -27,7 +26,9 @@
 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
 import org.onosproject.yangutils.utils.YangConstructType;
 
+import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
 import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
 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.constructListenerErrorMessage;
@@ -99,8 +100,8 @@
      * Sets the length restriction to type.
      *
      * @param listener listener's object
-     * @param type Yang type for which length restriction to be set
-     * @param ctx  context object of the grammar rule
+     * @param type     Yang type for which length restriction to be set
+     * @param ctx      context object of the grammar rule
      */
     private static void setLengthRestriction(TreeWalkListener listener, YangType type,
                                              GeneratedYangParser.LengthStatementContext ctx) {
@@ -115,10 +116,10 @@
             return;
         }
 
-        if (type.getDataType() != YangDataTypes.STRING) {
+        if (type.getDataType() != STRING && type.getDataType() != BINARY) {
             ParserException parserException = new ParserException("YANG file error : " +
                     YangConstructType.getYangConstructType(LENGTH_DATA) + " name " + ctx.length().getText() +
-                    " can be used to restrict the built-in type string or types derived from string.");
+                    " can be used to restrict the built-in type string/binary or types derived from string/binary.");
             parserException.setLine(ctx.getStart().getLine());
             parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
             throw parserException;
@@ -127,14 +128,18 @@
         YangRangeRestriction lengthRestriction = processLengthRestriction(null, ctx.getStart().getLine(),
                 ctx.getStart().getCharPositionInLine(), false, ctx.length().getText());
 
-        YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
+        if (type.getDataType() == STRING) {
+            YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
+            if (stringRestriction == null) {
+                stringRestriction = new YangStringRestriction();
+                type.setDataTypeExtendedInfo(stringRestriction);
+            }
 
-        if (stringRestriction == null) {
-            stringRestriction = new YangStringRestriction();
-            type.setDataTypeExtendedInfo(stringRestriction);
+            stringRestriction.setLengthRestriction(lengthRestriction);
+        } else {
+            type.setDataTypeExtendedInfo(lengthRestriction);
         }
 
-        stringRestriction.setLengthRestriction(lengthRestriction);
         listener.getParsedDataStack().push(lengthRestriction);
     }
 
@@ -143,7 +148,7 @@
      * It is called when parser exits from grammar rule (length).
      *
      * @param listener listener's object
-     * @param ctx context object of the grammar rule
+     * @param ctx      context object of the grammar rule
      */
     public static void processLengthRestrictionExit(TreeWalkListener listener,
                                                    GeneratedYangParser.LengthStatementContext ctx) {
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
index fd1bd84..a0005ba 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
@@ -16,7 +16,7 @@
 
 package org.onosproject.yangutils.parser.impl.listeners;
 
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
 import org.onosproject.yangutils.datamodel.YangModule;
 import org.onosproject.yangutils.datamodel.YangRevision;
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
index cfaa15f..2c97f30 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
@@ -16,7 +16,7 @@
 
 package org.onosproject.yangutils.parser.impl.listeners;
 
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import org.onosproject.yangutils.linker.impl.YangReferenceResolver;
 import org.onosproject.yangutils.datamodel.YangRevision;
 import org.onosproject.yangutils.datamodel.YangSubModule;
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
index e5b098b..6e25f1b 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
@@ -22,26 +22,24 @@
 import org.onosproject.yangutils.datamodel.YangLeafList;
 import org.onosproject.yangutils.datamodel.YangNode;
 import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangResolutionInfo;
 import org.onosproject.yangutils.datamodel.YangType;
 import org.onosproject.yangutils.datamodel.YangTypeDef;
 import org.onosproject.yangutils.datamodel.YangUnion;
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
 import org.onosproject.yangutils.parser.Parsable;
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
 import org.onosproject.yangutils.parser.exceptions.ParserException;
 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
 
-import static org.onosproject.yangutils.datamodel.ResolvableStatus.UNRESOLVED;
 import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
 import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
 import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangType;
+import static org.onosproject.yangutils.linker.impl.ResolvableStatus.UNRESOLVED;
 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;
@@ -81,10 +79,10 @@
      * (type), performs validation and updates the data model tree.
      *
      * @param listener listener's object
-     * @param ctx context object of the grammar rule
+     * @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);
@@ -190,6 +188,8 @@
                     YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
                     ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
 
+                    type.setResolvableStatus(UNRESOLVED);
+
                     // Add resolution information to the list
                     YangResolutionInfo resolutionInfo =
                             new YangResolutionInfo<YangType>(type, unionNode, errorLine, errorPosition);
@@ -211,13 +211,15 @@
                     YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
                     ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
 
+                    type.setResolvableStatus(UNRESOLVED);
+
                     // Add resolution information to the list
                     YangResolutionInfo resolutionInfo =
                             new YangResolutionInfo<YangType>(type, typeDef, errorLine, errorPosition);
                     addToResolutionList(resolutionInfo, ctx);
                 }
                 break;
-            //TODO: deviate replacement statement.case TYPEDEF_DATA: //TODO
+            //TODO: deviate replacement statement.
 
             default:
                 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
@@ -233,10 +235,10 @@
      * validations and update the data model tree.
      *
      * @param listener Listener's object
-     * @param ctx context object of the grammar rule
+     * @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);
@@ -252,15 +254,15 @@
      * Adds to resolution list.
      *
      * @param resolutionInfo resolution information
-     * @param ctx context object of the grammar rule
+     * @param ctx            context object of the grammar rule
      */
     private static void addToResolutionList(YangResolutionInfo<YangType> resolutionInfo,
-            GeneratedYangParser.TypeStatementContext ctx) {
+                                            GeneratedYangParser.TypeStatementContext ctx) {
         try {
             addResolutionInfo(resolutionInfo);
         } catch (DataModelException e) {
             throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
-                    TYPE_DATA, ctx.string().getText(), EXIT, e.getMessage()));
+                    TYPE_DATA, ctx.string().getText(), ENTRY, e.getMessage()));
         }
     }
 }
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java
index 1658eee..fd6523f 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java
@@ -26,7 +26,7 @@
 import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
 import org.onosproject.yangutils.datamodel.YangNotification;
 import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangResolutionInfo;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
 import org.onosproject.yangutils.datamodel.YangSubModule;
 import org.onosproject.yangutils.datamodel.YangUses;
 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;