[ONOS-4941][ONOS-4883][ONOS-4979]Grouping and uses interfile linking issue + defect fix

Change-Id: I5e8145f05d3ef570d4ecbbe885c93de172de0ea3
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
index 508ec54..754801b 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
@@ -172,7 +172,7 @@
                 ((YangReferenceResolver) yangNode)
                         .resolveInterFileLinking(ResolvableType.YANG_USES);
                 ((YangReferenceResolver) yangNode)
-                .resolveInterFileLinking(ResolvableType.YANG_AUGMENT);
+                        .resolveInterFileLinking(ResolvableType.YANG_AUGMENT);
                 ((YangReferenceResolver) yangNode)
                         .resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
                 ((YangReferenceResolver) yangNode)
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
index 5c680cd..d7f0428 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
@@ -1594,11 +1594,7 @@
             if (linkedNode != null) {
                 // Add the link to external entity.
                 addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
-                /*
-                 * Update the current reference resolver to external
-                 * module/sub-module containing the referred typedef/grouping.
-                 */
-                setCurReferenceResolver((YangReferenceResolver) yangInclude.getIncludedNode());
+
                 // Add the type/uses of referred typedef/grouping to the stack.
                 addUnresolvedRecursiveReferenceToStack(linkedNode);
                 return true;
@@ -1641,12 +1637,7 @@
                 if (linkedNode != null) {
                     // Add the link to external entity.
                     addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
-                    /*
-                     * Update the current reference resolver to external
-                     * module/sub-module containing the referred
-                     * typedef/grouping.
-                     */
-                    setCurReferenceResolver((YangReferenceResolver) yangImport.getImportedNode());
+
                     // Add the type/uses of referred typedef/grouping to the
                     // stack.
                     addUnresolvedRecursiveReferenceToStack(linkedNode);
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
index 5e55e15..72e7995 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
@@ -1835,136 +1835,94 @@
     void exitCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext currentContext);
 
     /**
-     * Enters a parse tree produced by GeneratedYangParser for grammar rule annotation statement.
+     * Enters a parse tree produced by GeneratedYangParser for grammar rule compiler annotation body statement.
      *
      * @param currentContext current context in the parsed tree
      */
-    void enterAnnotationStatement(GeneratedYangParser.AnnotationStatementContext currentContext);
-
-    /**
-     * Exits a parse tree produced by GeneratedYangParser for grammar rule annotation statement.
-     *
-     * @param currentContext current context in the parsed tree
-     */
-    void exitAnnotationStatement(GeneratedYangParser.AnnotationStatementContext currentContext);
-
-    /**
-     * Enters a parse tree produced by GeneratedYangParser for grammar rule annotation type.
-     *
-     * @param currentContext current context in the parsed tree
-     */
-    void enterAnnotationType(GeneratedYangParser.AnnotationTypeContext currentContext);
-
-    /**
-     * Exits a parse tree produced by GeneratedYangParser for grammar rule annotation type.
-     *
-     * @param currentContext current context in the parsed tree
-     */
-    void exitAnnotationType(GeneratedYangParser.AnnotationTypeContext currentContext);
-
-    /**
-     * Enters a parse tree produced by GeneratedYangParser for grammar rule
-     * annotation parameter specification.
-     *
-     * @param currentContext current context in the parsed tree
-     */
-    void enterAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext
-                                                       currentContext);
-
-    /**
-     * Exits a parse tree produced by GeneratedYangParser for grammar rule
-     * annotation parameter specification.
-     *
-     * @param currentContext current context in the parsed tree
-     */
-    void exitAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext
+    void enterCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext
                                                       currentContext);
 
     /**
-     * Enters a parse tree produced by GeneratedYangParser for grammar rule
-     * annotation parameter specification argument.
+     * Exits a parse tree produced by GeneratedYangParser for grammar rule compiler annotation body statement.
      *
      * @param currentContext current context in the parsed tree
      */
-    void enterAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
-                                                          currentContext);
+    void exitCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext
+                                                     currentContext);
 
     /**
-     * Exits a parse tree produced by GeneratedYangParser for grammar rule
-     * annotation parameter specification argument.
+     * Enters a parse tree produced by GeneratedYangParser for grammar rule app data structure statement.
      *
      * @param currentContext current context in the parsed tree
      */
-    void exitAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
-                                                         currentContext);
+    void enterAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext
+                                                currentContext);
 
     /**
-     * Enters a parse tree produced by GeneratedYangParser for grammar rule annotation parameter instance.
+     * Exits a parse tree produced by GeneratedYangParser for grammar rule app data structure statement.
      *
      * @param currentContext current context in the parsed tree
      */
-    void enterAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext
-                                             currentContext);
+    void exitAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext currentContext);
 
     /**
-     * Exits a parse tree produced by GeneratedYangParser for grammar rule annotation parameter instance.
+     * Enters a parse tree produced by GeneratedYangParser for grammar rule app data structure.
      *
      * @param currentContext current context in the parsed tree
      */
-    void exitAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext
-                                            currentContext);
+    void enterAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext);
+
+    /**
+     * Exits a parse tree produced by GeneratedYangParser for grammar rule app data strcuture.
+     *
+     * @param currentContext current context in the parsed tree
+     */
+    void exitAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext);
+
+    /**
+     * Enters a parse tree produced by GeneratedYangParser for grammar rule app extended statement.
+     *
+     * @param currentContext current context in the parsed tree
+     */
+    void enterAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext);
+
+    /**
+     * Exits a parse tree produced by GeneratedYangParser for grammar rule app extended statement.
+     *
+     * @param currentContext current context in the parsed tree
+     */
+    void exitAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext);
+
+    /**
+     * Enters a parse tree produced by GeneratedYangParser for grammar rule extended name.
+     *
+     * @param currentContext current context in the parsed tree
+     */
+    void enterExtendedName(GeneratedYangParser.ExtendedNameContext currentContext);
+
+    /**
+     * Exits a parse tree produced by GeneratedYangParser for grammar rule extended name.
+     *
+     * @param currentContext current context in the parsed tree
+     */
+    void exitExtendedName(GeneratedYangParser.ExtendedNameContext currentContext);
+
 
     /**
      * Enters a parse tree produced by GeneratedYangParser for grammar rule
-     * annotation parameter type identifier.
+     * data structure key statement.
      *
      * @param currentContext current context in the parsed tree
      */
-    void enterAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext
-                                                   currentContext);
+    void enterDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext currentContext);
 
     /**
      * Exits a parse tree produced by GeneratedYangParser for grammar rule
-     * annotation parameter type identifier.
+     * data structure key statement.
      *
      * @param currentContext current context in the parsed tree
      */
-    void exitAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext
-                                                  currentContext);
-
-    /**
-     * Enters a parse tree produced by GeneratedYangParser for grammar rule
-     * annotation parameter type value.
-     *
-     * @param currentContext current context in the parsed tree
-     */
-    void enterAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext
-                                              currentContext);
-
-    /**
-     * Exits a parse tree produced by GeneratedYangParser for grammar rule
-     * annotation parameter type value.
-     *
-     * @param currentContext current context in the parsed tree
-     */
-    void exitAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext
-                                             currentContext);
-
-    /**
-     * Enters a parse tree produced by GeneratedYangParser for grammar rule annotation identifier.
-     *
-     * @param currentContext current context in the parsed tree
-     */
-    void enterAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext
-                                           currentContext);
-
-    /**
-     * Exits a parse tree produced by GeneratedYangParser for grammar rule annotation identifier.
-     *
-     * @param currentContext current context in the parsed tree
-     */
-    void exitAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext
-                                          currentContext);
+    void exitDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext currentContext);
 
     /**
      * Enters a parse tree produced by GeneratedYangParser for grammar rule require instance.
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
index 2b9021b..116f06d 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
@@ -24,6 +24,8 @@
 import org.onosproject.yangutils.datamodel.utils.YangConstructType;
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener;
 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.impl.listeners.AppDataStructureListener;
+import org.onosproject.yangutils.parser.impl.listeners.AppExtendedNameListener;
 import org.onosproject.yangutils.parser.impl.listeners.ArgumentListener;
 import org.onosproject.yangutils.parser.impl.listeners.AugmentListener;
 import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener;
@@ -33,9 +35,11 @@
 import org.onosproject.yangutils.parser.impl.listeners.BitsListener;
 import org.onosproject.yangutils.parser.impl.listeners.CaseListener;
 import org.onosproject.yangutils.parser.impl.listeners.ChoiceListener;
+import org.onosproject.yangutils.parser.impl.listeners.CompilerAnnotationListener;
 import org.onosproject.yangutils.parser.impl.listeners.ConfigListener;
 import org.onosproject.yangutils.parser.impl.listeners.ContactListener;
 import org.onosproject.yangutils.parser.impl.listeners.ContainerListener;
+import org.onosproject.yangutils.parser.impl.listeners.DataStructureKeyListener;
 import org.onosproject.yangutils.parser.impl.listeners.Decimal64Listener;
 import org.onosproject.yangutils.parser.impl.listeners.DefaultListener;
 import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener;
@@ -1428,95 +1432,72 @@
 
     @Override
     public void enterCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
-        // TODO: implement the method.
+        CompilerAnnotationListener.processCompilerAnnotationEntry(this, ctx);
     }
 
     @Override
     public void exitCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
-        // TODO: implement the method.
+        CompilerAnnotationListener.processCompilerAnnotationExit(this, ctx);
     }
 
     @Override
-    public void enterAnnotationStatement(GeneratedYangParser.AnnotationStatementContext ctx) {
-        // TODO: implement the method.
+    public void enterCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext ctx) {
+        // do nothing
     }
 
     @Override
-    public void exitAnnotationStatement(GeneratedYangParser.AnnotationStatementContext ctx) {
-        // TODO: implement the method.
+    public void exitCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext ctx) {
+        // do nothing
     }
 
     @Override
-    public void enterAnnotationType(GeneratedYangParser.AnnotationTypeContext ctx) {
-        // TODO: implement the method.
+    public void enterAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext ctx) {
+        AppDataStructureListener.processAppDataStructureEntry(this, ctx);
     }
 
     @Override
-    public void exitAnnotationType(GeneratedYangParser.AnnotationTypeContext ctx) {
-        // TODO: implement the method.
+    public void exitAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext ctx) {
+        AppDataStructureListener.processAppDataStructureExit(this, ctx);
     }
 
     @Override
-    public void enterAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext
-                                                              ctx) {
-        // TODO: implement the method.
+    public void enterAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext) {
+        // do nothing
     }
 
     @Override
-    public void exitAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext ctx) {
-        // TODO: implement the method.
+    public void exitAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext) {
+        // do nothing
     }
 
     @Override
-    public void enterAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
-                                                                 ctx) {
-        // TODO: implement the method.
+    public void enterAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext) {
+        AppExtendedNameListener.processAppExtendedNameEntry(this, currentContext);
     }
 
     @Override
-    public void exitAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
-                                                                ctx) {
-        // TODO: implement the method.
+    public void exitAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext) {
+        // TODO : to be implemented
     }
 
     @Override
-    public void enterAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext ctx) {
-        // TODO: implement the method.
+    public void enterExtendedName(GeneratedYangParser.ExtendedNameContext currentContext) {
+        // do nothing
     }
 
     @Override
-    public void exitAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext ctx) {
-        // TODO: implement the method.
+    public void exitExtendedName(GeneratedYangParser.ExtendedNameContext currentContext) {
+        // do nothing
     }
 
     @Override
-    public void enterAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext ctx) {
-        // TODO: implement the method.
+    public void enterDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext ctx) {
+        DataStructureKeyListener.processDataStructureKeyEntry(this, ctx);
     }
 
     @Override
-    public void exitAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext ctx) {
-        // TODO: implement the method.
-    }
-
-    @Override
-    public void enterAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext ctx) {
-        // TODO: implement the method.
-    }
-
-    @Override
-    public void exitAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext ctx) {
-        // TODO: implement the method.
-    }
-
-    @Override
-    public void enterAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext ctx) {
-        // TODO: implement the method.
-    }
-
-    @Override
-    public void exitAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext ctx) {
-        // TODO: implement the method.
+    public void exitDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext ctx) {
+        // do nothing
     }
 
     @Override
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java
new file mode 100644
index 0000000..e6628b3
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java
@@ -0,0 +1,112 @@
+/*
+ * 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.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangAppDataStructure;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
+import org.onosproject.yangutils.datamodel.YangDataStructure;
+import org.onosproject.yangutils.datamodel.utils.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.YangDataStructure.getType;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.APP_DATA_STRUCTURE;
+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;
+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.ListenerUtil.getValidPrefix;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *   app-data-structure-stmt = prefix:app-data-structure-keyword string
+ *                         (";" /
+ *                          "{"
+ *                              [data-structure-key-stmt stmtsep]
+ *                          "}")
+ *
+ * ANTLR grammar rule
+ *   appDataStructureStatement : APP_DATA_STRUCTURE appDataStructure (STMTEND | (LEFT_CURLY_BRACE
+ *       dataStructureKeyStatement? RIGHT_CURLY_BRACE));
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "app-data-structure"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class AppDataStructureListener {
+
+    /**
+     * Creates a new app-data-structure listener.
+     */
+    private AppDataStructureListener() {
+    }
+
+    /**
+     * Performs validation and updates the data model tree. It is called when parser receives an
+     * input matching the grammar rule(app-data-structure).
+     *
+     * @param listener listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processAppDataStructureEntry(TreeWalkListener listener,
+                                                    GeneratedYangParser.AppDataStructureStatementContext ctx) {
+
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_DATA_STRUCTURE, "", ENTRY);
+
+        String prefix = getValidPrefix(ctx.APP_DATA_STRUCTURE().getText(), APP_DATA_STRUCTURE, ctx);
+        YangDataStructure dataStructure = getType(ctx.appDataStructure().getText());
+
+        YangAppDataStructure appDataStructure = new YangAppDataStructure();
+        appDataStructure.setPrefix(prefix);
+        appDataStructure.setDataStructure(dataStructure);
+
+        Parsable curData = listener.getParsedDataStack().peek();
+        if (curData instanceof YangCompilerAnnotation) {
+            YangCompilerAnnotation compilerAnnotation = ((YangCompilerAnnotation) curData);
+            compilerAnnotation.setYangAppDataStructure(appDataStructure);
+            listener.getParsedDataStack().push(appDataStructure);
+        } else {
+            throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, APP_DATA_STRUCTURE,
+                    "", ENTRY));
+        }
+    }
+
+    /**
+     * Performs validation and updates the data model tree. It is called when parser
+     * exits from grammar rule (app-data-structure).
+     *
+     * @param listener listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processAppDataStructureExit(TreeWalkListener listener,
+                                                   GeneratedYangParser.AppDataStructureStatementContext ctx) {
+
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_DATA_STRUCTURE, "", EXIT);
+        if (!(listener.getParsedDataStack().peek() instanceof YangAppDataStructure)) {
+            throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, APP_DATA_STRUCTURE,
+                    "", EXIT));
+        }
+        listener.getParsedDataStack().pop();
+    }
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java
new file mode 100644
index 0000000..3ec31c7
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java
@@ -0,0 +1,83 @@
+/*
+ * 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.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangAppExtendedName;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
+import org.onosproject.yangutils.datamodel.utils.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.utils.YangConstructType.APP_EXTENDED_NAME_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+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_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidPrefix;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *   app-extended-stmt = prefix:app-extended-name-keyword string ";"
+ *
+ * ANTLR grammar rule
+ * appExtendedStatement : APP_EXTENDED extendedName STMTEND;
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "app-extended-name"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class AppExtendedNameListener {
+
+    /**
+     * Creates a new app-extended-name listener.
+     */
+    private AppExtendedNameListener() {
+    }
+
+    /**
+     * Performs validation and updates the data model tree. It is called when parser receives an
+     * input matching the grammar rule(app-extended-name).
+     *
+     * @param listener listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processAppExtendedNameEntry(TreeWalkListener listener,
+                                                   GeneratedYangParser.AppExtendedStatementContext ctx) {
+
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_EXTENDED_NAME_DATA, ctx.extendedName().getText(), ENTRY);
+
+        String prefix = getValidPrefix(ctx.APP_EXTENDED().getText(), APP_EXTENDED_NAME_DATA, ctx);
+        YangAppExtendedName extendedName = new YangAppExtendedName();
+        extendedName.setPrefix(prefix);
+        extendedName.setYangAppExtendedName(removeQuotesAndHandleConcat(ctx.extendedName().getText()));
+
+        Parsable curData = listener.getParsedDataStack().peek();
+        if (curData instanceof YangCompilerAnnotation) {
+            YangCompilerAnnotation compilerAnnotation = ((YangCompilerAnnotation) curData);
+            compilerAnnotation.setYangAppExtendedName(extendedName);
+        } else {
+            throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, APP_EXTENDED_NAME_DATA,
+                    ctx.extendedName().getText(), ENTRY));
+        }
+    }
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
new file mode 100644
index 0000000..c89e99a
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
@@ -0,0 +1,118 @@
+/*
+ * 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.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.utils.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.utils.YangConstructType.COMPILER_ANNOTATION_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.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.ListenerUtil.getValidPrefix;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *   compiler-annotation-stmt = prefix:compiler-annotation-keyword string
+ *                          "{"
+ *                              [app-data-structure-stmt stmtsep]
+ *                              [app-extended-stmt stmtsep]
+ *                          "}"
+ *
+ * ANTLR grammar rule
+ *   compilerAnnotationStatement : COMPILER_ANNOTATION string LEFT_CURLY_BRACE
+ *        compilerAnnotationBodyStatement RIGHT_CURLY_BRACE;
+ *
+ *   compilerAnnotationBodyStatement : appDataStructureStatement? appExtendedStatement? ;
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "compiler-annotation"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class CompilerAnnotationListener {
+
+    /**
+     * Creates a new compiler-annotation listener.
+     */
+    private CompilerAnnotationListener() {
+    }
+
+    /**
+     * Performs validation and updates the data model tree. It is called when parser receives an
+     * input matching the grammar rule(compiler-annotation).
+     *
+     * @param listener listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processCompilerAnnotationEntry(TreeWalkListener listener,
+                                                      GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
+        // Check for stack to be non empty.
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, COMPILER_ANNOTATION_DATA, ctx.string().getText(), ENTRY);
+        String prefix = getValidPrefix(ctx.COMPILER_ANNOTATION().getText(), COMPILER_ANNOTATION_DATA, ctx);
+
+        YangCompilerAnnotation compilerAnnotation = new YangCompilerAnnotation();
+        compilerAnnotation.setPrefix(prefix);
+        compilerAnnotation.setPath(removeQuotesAndHandleConcat(ctx.string().getText()));
+
+        Parsable curData = listener.getParsedDataStack().peek();
+        switch (curData.getYangConstructType()) {
+            case MODULE_DATA:
+                YangModule module = ((YangModule) curData);
+                module.addCompilerAnnotation(compilerAnnotation);
+                break;
+            case SUB_MODULE_DATA:
+                YangSubModule subModule = ((YangSubModule) curData);
+                subModule.addCompilerAnnotation(compilerAnnotation);
+                break;
+            default:
+                throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, COMPILER_ANNOTATION_DATA,
+                        ctx.string().getText(), ENTRY));
+        }
+        listener.getParsedDataStack().push(compilerAnnotation);
+    }
+
+    /**
+     * Performs validation and updates the data model tree. It is called when parser
+     * exits from grammar rule (compiler-annotation).
+     *
+     * @param listener listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processCompilerAnnotationExit(TreeWalkListener listener,
+                                                     GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
+
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, COMPILER_ANNOTATION_DATA, ctx.string().getText(), EXIT);
+        if (!(listener.getParsedDataStack().peek() instanceof YangCompilerAnnotation)) {
+            throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, COMPILER_ANNOTATION_DATA,
+                    ctx.string().getText(), EXIT));
+        }
+        listener.getParsedDataStack().pop();
+    }
+}
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DataStructureKeyListener.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DataStructureKeyListener.java
new file mode 100644
index 0000000..65fc50b
--- /dev/null
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DataStructureKeyListener.java
@@ -0,0 +1,87 @@
+/*
+ * 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.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangAppDataStructure;
+import org.onosproject.yangutils.datamodel.utils.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.utils.YangConstructType.KEY_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+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_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ *   data-structure-key-stmt = prefix:key-keyword string ";"
+ *
+ * ANTLR grammar rule
+ *   dataStructureKeyStatement : DATA_STRUCTURE_KEY string STMTEND;
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "key"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class DataStructureKeyListener {
+
+    /**
+     * Creates a new data-structure-key listener.
+     */
+    private DataStructureKeyListener() {
+    }
+
+    /**
+     * Performs validation and updates the data model tree. It is called when parser receives an
+     * input matching the grammar rule(key).
+     *
+     * @param listener listener's object
+     * @param ctx      context object of the grammar rule
+     */
+    public static void processDataStructureKeyEntry(TreeWalkListener listener,
+                                                    GeneratedYangParser.DataStructureKeyStatementContext ctx) {
+
+        // Check for stack to be non empty.
+        checkStackIsNotEmpty(listener, MISSING_HOLDER, KEY_DATA, ctx.string().getText(), ENTRY);
+
+        Parsable tmpData = listener.getParsedDataStack().peek();
+        if (listener.getParsedDataStack().peek() instanceof YangAppDataStructure) {
+            YangAppDataStructure dataStructure = (YangAppDataStructure) tmpData;
+            String tmpKeyValue = removeQuotesAndHandleConcat(ctx.string().getText());
+            if (tmpKeyValue.contains(SPACE)) {
+                String[] keyValues = tmpKeyValue.split(SPACE);
+                for (String keyValue : keyValues) {
+                    dataStructure.addKey(keyValue);
+                }
+            } else {
+                dataStructure.addKey(tmpKeyValue);
+            }
+        } else {
+            throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, KEY_DATA, ctx.string().getText(),
+                    ENTRY));
+        }
+    }
+}
+
diff --git a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index aa38b87..5fe0970 100644
--- a/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/utils/yangutils/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -1026,4 +1026,28 @@
             throw parserException;
         }
     }
+
+    /**
+     * Checks and return valid prefix.
+     *
+     * @param inputString   string from yang file
+     * @param yangConstruct yang construct for creating error message
+     * @param ctx           yang construct's context to get the line number and character position
+     * @return valid prefix
+     */
+    public static String getValidPrefix(String inputString,
+                                        YangConstructType yangConstruct, ParserRuleContext ctx) {
+        String tmpPrefixString = removeQuotesAndHandleConcat(inputString);
+        String[] tmpData = tmpPrefixString.split(Pattern.quote(COLON));
+        if (tmpData.length == 2) {
+            return tmpData[0];
+        } else {
+            ParserException parserException = new ParserException("YANG file error : " +
+                    YangConstructType.getYangConstructType(yangConstruct) + " name " + inputString +
+                    " is not valid.");
+            parserException.setLine(ctx.getStart().getLine());
+            parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+            throw parserException;
+        }
+    }
 }