[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/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));
+        }
+    }
+}
+