[ONOS-4762][ONOS-4601]Grammar for meta data +  Union defect fix

Change-Id: I8f78127e5b292cca6a79b32d496c2602c9105acd
diff --git a/utils/yangutils/plugin/src/main/resources/GeneratedYang.g4 b/utils/yangutils/plugin/src/main/resources/GeneratedYang.g4
index 55a7a35..36b38ff 100644
--- a/utils/yangutils/plugin/src/main/resources/GeneratedYang.g4
+++ b/utils/yangutils/plugin/src/main/resources/GeneratedYang.g4
@@ -237,34 +237,13 @@
      *                            [status-stmt stmtsep]
      *                            [description-stmt stmtsep]
      *                            [reference-stmt stmtsep]
+     *                            [compiler-annotation-stmt stmtsep]
      *                        "}")
+     * TODO : 0..1 occurance to be checked in listener
      */
     extensionStatement : EXTENSION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE extensionBody RIGHT_CURLY_BRACE);
-    extensionBody : argumentStatement? statusStatement? descriptionStatement? referenceStatement?
-                   | argumentStatement? statusStatement? referenceStatement? descriptionStatement?
-                   | argumentStatement? descriptionStatement? statusStatement? referenceStatement?
-                   | argumentStatement? descriptionStatement? referenceStatement? statusStatement?
-                   | argumentStatement? referenceStatement? descriptionStatement? statusStatement?
-                   | argumentStatement? referenceStatement? statusStatement? descriptionStatement?
-                   | statusStatement? referenceStatement? argumentStatement? descriptionStatement?
-                   | statusStatement? referenceStatement? descriptionStatement? argumentStatement?
-                   | statusStatement? descriptionStatement? referenceStatement? argumentStatement?
-                   | statusStatement? descriptionStatement? argumentStatement? referenceStatement?
-                   | statusStatement? argumentStatement? referenceStatement? descriptionStatement?
-                   | statusStatement? argumentStatement? descriptionStatement? referenceStatement?
-                   | descriptionStatement? argumentStatement? statusStatement? referenceStatement?
-                   | descriptionStatement? argumentStatement? referenceStatement? statusStatement?
-                   | descriptionStatement? statusStatement? argumentStatement? referenceStatement?
-                   | descriptionStatement? statusStatement? referenceStatement? argumentStatement?
-                   | descriptionStatement? referenceStatement? statusStatement? argumentStatement?
-                   | descriptionStatement? referenceStatement? argumentStatement? statusStatement?
-                   | referenceStatement? descriptionStatement? argumentStatement? statusStatement?
-                   | referenceStatement? descriptionStatement? statusStatement? argumentStatement?
-                   | referenceStatement? statusStatement? argumentStatement? descriptionStatement?
-                   | referenceStatement? statusStatement? descriptionStatement? argumentStatement?
-                   | referenceStatement? argumentStatement? descriptionStatement? statusStatement?
-                   | referenceStatement? argumentStatement? statusStatement? descriptionStatement?
-                   ;
+    extensionBody : (argumentStatement | statusStatement | descriptionStatement
+                  | referenceStatement | compilerAnnotationStatement)* ;
 
     /**
      * argument-stmt       = argument-keyword sep identifier-arg-str optsep
@@ -291,35 +270,13 @@
      *                            [status-stmt stmtsep]
      *                            [description-stmt stmtsep]
      *                            [reference-stmt stmtsep]
+     *                            [compiler-annotation-stmt stmtsep]
      *                        "}")
+     * TODO : 0..1 occurance to be checked in listener
      */
     identityStatement : IDENTITY_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE identityBody RIGHT_CURLY_BRACE);
-    identityBody : baseStatement? statusStatement? descriptionStatement? referenceStatement?
-                  | baseStatement? statusStatement? referenceStatement? descriptionStatement?
-                  | baseStatement? descriptionStatement? statusStatement? referenceStatement?
-                  | baseStatement? descriptionStatement? referenceStatement? statusStatement?
-                  | baseStatement? referenceStatement? descriptionStatement? statusStatement?
-                  | baseStatement? referenceStatement? statusStatement? descriptionStatement?
-                  | referenceStatement? baseStatement? statusStatement? descriptionStatement?
-                  | referenceStatement? baseStatement? descriptionStatement? statusStatement?
-                  | referenceStatement? statusStatement? baseStatement? descriptionStatement?
-                  | referenceStatement? statusStatement? descriptionStatement? baseStatement?
-                  | referenceStatement? descriptionStatement? statusStatement? baseStatement?
-                  | referenceStatement? descriptionStatement? baseStatement? statusStatement?
-                  | descriptionStatement? referenceStatement? statusStatement? baseStatement?
-                  | descriptionStatement? referenceStatement? statusStatement? baseStatement?
-                  | descriptionStatement? referenceStatement? baseStatement? statusStatement?
-                  | descriptionStatement? statusStatement? baseStatement? referenceStatement?
-                  | descriptionStatement? statusStatement? referenceStatement? baseStatement?
-                  | descriptionStatement? baseStatement? referenceStatement? statusStatement?
-                  | descriptionStatement? baseStatement? statusStatement? referenceStatement?
-                  | statusStatement? baseStatement? descriptionStatement? referenceStatement?
-                  | statusStatement? baseStatement? referenceStatement? descriptionStatement?
-                  | statusStatement? descriptionStatement? baseStatement? referenceStatement?
-                  | statusStatement? descriptionStatement? referenceStatement? baseStatement?
-                  | statusStatement? referenceStatement? descriptionStatement? baseStatement?
-                  | statusStatement? referenceStatement? baseStatement? descriptionStatement?
-                  ;
+    identityBody : (baseStatement | statusStatement | descriptionStatement | referenceStatement
+                 | compilerAnnotationStatement)*;
 
     /**
      * base-stmt           = base-keyword sep identifier-ref-arg-str
@@ -337,34 +294,13 @@
      *                             [status-stmt stmtsep]
      *                             [description-stmt stmtsep]
      *                             [reference-stmt stmtsep]
+     *                             [compiler-annotation-stmt stmtsep]
      *                         "}")
+     * TODO : 0..1 occurance to be checked in listener
      */
     featureStatement : FEATURE_KEYWORD string (STMTEND | LEFT_CURLY_BRACE featureBody RIGHT_CURLY_BRACE);
-    featureBody : ifFeatureStatement* statusStatement? descriptionStatement? referenceStatement?
-                 | ifFeatureStatement* statusStatement? referenceStatement? descriptionStatement?
-                 | ifFeatureStatement* descriptionStatement? statusStatement? referenceStatement?
-                 | ifFeatureStatement* descriptionStatement? referenceStatement? statusStatement?
-                 | ifFeatureStatement* referenceStatement? statusStatement? descriptionStatement?
-                 | ifFeatureStatement* referenceStatement? descriptionStatement? statusStatement?
-                 | statusStatement? ifFeatureStatement* descriptionStatement? referenceStatement?
-                 | statusStatement? ifFeatureStatement* referenceStatement? descriptionStatement?
-                 | statusStatement? descriptionStatement? ifFeatureStatement* referenceStatement?
-                 | statusStatement? descriptionStatement? referenceStatement? ifFeatureStatement*
-                 | statusStatement? referenceStatement? ifFeatureStatement* descriptionStatement?
-                 | statusStatement? referenceStatement? descriptionStatement? ifFeatureStatement*
-                 | descriptionStatement? ifFeatureStatement* statusStatement? referenceStatement?
-                 | descriptionStatement? ifFeatureStatement* referenceStatement? statusStatement?
-                 | descriptionStatement? statusStatement? ifFeatureStatement* referenceStatement?
-                 | descriptionStatement? statusStatement? referenceStatement? ifFeatureStatement*
-                 | descriptionStatement? referenceStatement* statusStatement? ifFeatureStatement*
-                 | descriptionStatement? referenceStatement* ifFeatureStatement? statusStatement?
-                 | referenceStatement? ifFeatureStatement* statusStatement? descriptionStatement?
-                 | referenceStatement? ifFeatureStatement* descriptionStatement? statusStatement?
-                 | referenceStatement? descriptionStatement? statusStatement? ifFeatureStatement*
-                 | referenceStatement? descriptionStatement? ifFeatureStatement* statusStatement?
-                 | referenceStatement? statusStatement? descriptionStatement? ifFeatureStatement*
-                 | referenceStatement? statusStatement? ifFeatureStatement* descriptionStatement?
-                 ;
+    featureBody : (ifFeatureStatement | statusStatement | descriptionStatement
+                | referenceStatement | compilerAnnotationStatement)* ;
 
     /**
      *  data-def-stmt       = container-stmt /
@@ -404,11 +340,13 @@
      *                             [status-stmt stmtsep]
      *                             [description-stmt stmtsep]
      *                             [reference-stmt stmtsep]
+     *                             [compiler-annotation-stmt stmtsep]
      *                           "}"
      * TODO : 0..1 occurance to be validated in listener
      */
     typedefStatement : TYPEDEF_KEYWORD identifier LEFT_CURLY_BRACE
-                   (typeStatement | unitsStatement | defaultStatement | statusStatement | descriptionStatement | referenceStatement)*
+                   (typeStatement | unitsStatement | defaultStatement | statusStatement | descriptionStatement
+                   | compilerAnnotationStatement | referenceStatement)*
                    RIGHT_CURLY_BRACE;
 
     /**
@@ -770,6 +708,7 @@
      *                            [status-stmt stmtsep]
      *                             [description-stmt stmtsep]
      *                             [reference-stmt stmtsep]
+     *                             [compiler-annotation-stmt stmtsep]
      *                             *((typedef-stmt /
      *                                grouping-stmt) stmtsep)
      *                             *(data-def-stmt stmtsep)
@@ -778,7 +717,7 @@
      */
     groupingStatement : GROUPING_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE
                       (statusStatement | descriptionStatement | referenceStatement | typedefStatement | groupingStatement
-                       | dataDefStatement)* RIGHT_CURLY_BRACE);
+                       | dataDefStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
 
     /**
      *  container-stmt      = container-keyword sep identifier-arg-str optsep
@@ -793,6 +732,7 @@
      *                             [status-stmt stmtsep]
      *                             [description-stmt stmtsep]
      *                             [reference-stmt stmtsep]
+     *                             [compiler-annotation-stmt stmtsep]
      *                             *((typedef-stmt /
      *                                grouping-stmt) stmtsep)
      *                             *(data-def-stmt stmtsep)
@@ -802,7 +742,7 @@
     containerStatement : CONTAINER_KEYWORD identifier
                      (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement | presenceStatement | configStatement
                      | statusStatement | descriptionStatement | referenceStatement | typedefStatement | groupingStatement
-                     | dataDefStatement)* RIGHT_CURLY_BRACE);
+                     | dataDefStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
 
     /**
      *  leaf-stmt           = leaf-keyword sep identifier-arg-str optsep
@@ -824,7 +764,7 @@
      */
     leafStatement : LEAF_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | typeStatement | unitsStatement
               | mustStatement | defaultStatement | configStatement | mandatoryStatement | statusStatement  | descriptionStatement
-              | referenceStatement)* RIGHT_CURLY_BRACE;
+              | referenceStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE;
 
     /**
      *  leaf-list-stmt      = leaf-list-keyword sep identifier-arg-str optsep
@@ -847,7 +787,7 @@
      */
     leafListStatement : LEAF_LIST_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | typeStatement
                      | unitsStatement | mustStatement | configStatement | minElementsStatement | maxElementsStatement | orderedByStatement
-                     | statusStatement | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE;
+                     | statusStatement | descriptionStatement | referenceStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE;
 
     /**
      *  list-stmt           = list-keyword sep identifier-arg-str optsep
@@ -873,7 +813,8 @@
      */
     listStatement : LIST_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement | keyStatement
               | uniqueStatement | configStatement | minElementsStatement | maxElementsStatement | orderedByStatement | statusStatement
-              | descriptionStatement | referenceStatement | typedefStatement | groupingStatement| dataDefStatement)* RIGHT_CURLY_BRACE;
+              | descriptionStatement | referenceStatement | typedefStatement | groupingStatement| dataDefStatement
+              | compilerAnnotationStatement)* RIGHT_CURLY_BRACE;
 
     /**
      *  key-stmt            = key-keyword sep key-arg-str stmtend
@@ -904,7 +845,7 @@
      */
     choiceStatement : CHOICE_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | defaultStatement
                   | configStatement | mandatoryStatement | statusStatement | descriptionStatement | referenceStatement | shortCaseStatement
-                  | caseStatement)* RIGHT_CURLY_BRACE);
+                  | caseStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
 
     /**
      *  short-case-stmt     = container-stmt /
@@ -949,7 +890,7 @@
      */
      anyxmlStatement : ANYXML_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement
                      | mustStatement | configStatement | mandatoryStatement | statusStatement | descriptionStatement
-                     | referenceStatement)* RIGHT_CURLY_BRACE);
+                     | referenceStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
 
     /**
      *  uses-stmt           = uses-keyword sep identifier-ref-arg-str optsep
@@ -961,13 +902,15 @@
      *                             [status-stmt stmtsep]
      *                             [description-stmt stmtsep]
      *                             [reference-stmt stmtsep]
+     *                             [compiler-annotation-stmt stmtsep]
      *                             *(refine-stmt stmtsep)
      *                             *(uses-augment-stmt stmtsep)
      *                         "}")
      * TODO : 0..1 occurance to be checked in listener
      */
     usesStatement : USES_KEYWORD string (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | statusStatement
-                | descriptionStatement | referenceStatement | refineStatement | augmentStatement)* RIGHT_CURLY_BRACE);
+                | descriptionStatement | referenceStatement | refineStatement | augmentStatement
+                | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
 
     /**
      *  refine-stmt         = refine-keyword sep refine-arg-str optsep
@@ -1082,7 +1025,8 @@
      * TODO : 0..1 occurance to be checked in listener
      */
     augmentStatement : AUGMENT_KEYWORD augment LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | statusStatement
-                   | descriptionStatement | referenceStatement | dataDefStatement  | caseStatement)* RIGHT_CURLY_BRACE;
+                   | descriptionStatement | referenceStatement | dataDefStatement  | caseStatement
+                   | compilerAnnotationStatement)* RIGHT_CURLY_BRACE;
 
     /**
      *  when-stmt           = when-keyword sep string optsep
@@ -1110,10 +1054,13 @@
      *                                grouping-stmt) stmtsep)
      *                             [input-stmt stmtsep]
      *                             [output-stmt stmtsep]
+     *                             [compiler-annotation-stmt stmtsep]
      *                         "}")
+     * TODO : 0..1 occurance to be checked in listener
      */
-    rpcStatement : RPC_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement | descriptionStatement
-                | referenceStatement | typedefStatement | groupingStatement | inputStatement | outputStatement)* RIGHT_CURLY_BRACE);
+    rpcStatement : RPC_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement
+                 | descriptionStatement | referenceStatement | typedefStatement | groupingStatement | inputStatement
+                 | outputStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
 
     /**
      * input-stmt          = input-keyword optsep
@@ -1147,6 +1094,7 @@
      *                             [status-stmt stmtsep]
      *                             [description-stmt stmtsep]
      *                             [reference-stmt stmtsep]
+     *                             [compiler-annotation-stmt stmtsep]
      *                             *((typedef-stmt /
      *                                grouping-stmt) stmtsep)
      *                             *(data-def-stmt stmtsep)
@@ -1155,7 +1103,7 @@
      */
      notificationStatement : NOTIFICATION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement
                            | statusStatement | descriptionStatement | referenceStatement | typedefStatement
-                           | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE);
+                           | groupingStatement | dataDefStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
 
     /**
      *  deviation-stmt      = deviation-keyword sep
@@ -1164,6 +1112,7 @@
      *                            ;; these stmts can appear in any order
      *                            [description-stmt stmtsep]
      *                            [reference-stmt stmtsep]
+     *                            [compiler-annotation-stmt stmtsep]
      *                            (deviate-not-supported-stmt /
      *                              1*(deviate-add-stmt /
      *                                 deviate-replace-stmt /
@@ -1173,7 +1122,7 @@
      */
     deviationStatement: DEVIATION_KEYWORD deviation LEFT_CURLY_BRACE (descriptionStatement | referenceStatement
                       | deviateNotSupportedStatement | deviateAddStatement | deviateReplaceStatement
-                      | deviateDeleteStatement)* RIGHT_CURLY_BRACE;
+                      | deviateDeleteStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE;
 
     /**
      * deviate-not-supported-stmt =
@@ -1233,11 +1182,68 @@
                            defaultStatement? configStatement? mandatoryStatement? minElementsStatement?
                            maxElementsStatement? RIGHT_CURLY_BRACE));
 
+    /**
+     * compiler-annotation-stmt = compiler-annotation-keyword optsep
+     *                    "{" stmtsep
+     *                        ;; these stmts can appear in any order
+     *                        *(if-feature-stmt stmtsep)
+     *                         [status-stmt stmtsep]
+     *                         [units-stmt stmtsep]
+     *                         [reference-stmt stmtsep]
+     *                         1*(compiler-annotation-stmt stmtsep)
+     *                    "}"
+     */
+    compilerAnnotationStatement : COMPILER_ANNOTATION_KEYWORD LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement
+                                | unitsStatement | referenceStatement | annotationStatement)*
+                                  RIGHT_CURLY_BRACE;
+
+    /**
+     * annotation-stmt = "@" annotation-type [annotation-parameter-specification] ";"
+     */
+    annotationStatement : annotationType annotationParameterSpecification? STMTEND;
+
+    /**
+     * annotation-type = identifier
+     */
+    annotationType : annotationIdentifier;
+
+    /**
+     * annotation-parameter-specification = "(" optsep annotation-parameter-specification-arg optsep ")"
+     */
+    annotationParameterSpecification : LEFT_ROUND_BRACE annotationParameterSpecificationArg RIGHT_ROUND_BRACE;
+
+    /**
+     * annotation-parameter-specification-arg = annotation-para-type-value
+     *                                     / annotation-para-instance *("," annotation-para-instance)
+     */
+    annotationParameterSpecificationArg : annotationParaTypeValue
+                                        | annotationParaInstance (COMMA annotationParaInstance)*;
+
+    /**
+     * annotation-para-instance = annotation-para-type-identifier optsep "=" optsep annotation-para-type-value
+     */
+    annotationParaInstance : annotationParaTypeIdentifier EQUAL annotationParaTypeValue;
+
+    /**
+     * annotation-para-type-identifier = identifier
+     */
+    annotationParaTypeIdentifier : identifier;
+
+    /**
+     * annotation-para-type-value = identifier
+     */
+    annotationParaTypeValue : identifier;
+
     string : STRING (PLUS STRING)*
            | IDENTIFIER
            | INTEGER
            | yangConstruct;
 
+    annotationIdentifier : STRING (PLUS STRING)*
+                         | ANNOTATION_IDENTIFIER
+                         | IDENTIFIER
+                         | yangConstruct;
+
     identifier : STRING (PLUS STRING)*
                | IDENTIFIER
                | yangConstruct;
@@ -1296,4 +1302,5 @@
                   | UNITS_KEYWORD | USES_KEYWORD | VALUE_KEYWORD | WHEN_KEYWORD | YANG_VERSION_KEYWORD
                   | YIN_ELEMENT_KEYWORD | ADD_KEYWORD | CURRENT_KEYWORD | DELETE_KEYWORD | DEPRECATED_KEYWORD
                   | FALSE_KEYWORD | MAX_KEYWORD | MIN_KEYWORD | NOT_SUPPORTED_KEYWORD | OBSOLETE_KEYWORD
-                  | REPLACE_KEYWORD | SYSTEM_KEYWORD | TRUE_KEYWORD | UNBOUNDED_KEYWORD | USER_KEYWORD;
\ No newline at end of file
+                  | REPLACE_KEYWORD | SYSTEM_KEYWORD | TRUE_KEYWORD | UNBOUNDED_KEYWORD | USER_KEYWORD
+                  | COMPILER_ANNOTATION_KEYWORD;
diff --git a/utils/yangutils/plugin/src/main/resources/YangLexer.g4 b/utils/yangutils/plugin/src/main/resources/YangLexer.g4
index da20fd8..d1f7fea 100644
--- a/utils/yangutils/plugin/src/main/resources/YangLexer.g4
+++ b/utils/yangutils/plugin/src/main/resources/YangLexer.g4
@@ -100,6 +100,7 @@
     TRUE_KEYWORD        : 'true';
     UNBOUNDED_KEYWORD   : 'unbounded';
     USER_KEYWORD        : 'user';
+    COMPILER_ANNOTATION_KEYWORD : 'compiler-annotation';
 
     // Lexer tokens to be skipped
     COMMENT
@@ -116,11 +117,18 @@
     DATE_ARG            : DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT DIGIT;
     LEFT_CURLY_BRACE    : '{';
     RIGHT_CURLY_BRACE   : '}';
+    LEFT_ROUND_BRACE    : '(';
+    RIGHT_ROUND_BRACE   : ')';
+    ANNOTATION_START    : '@';
+    ANNOTATION_IDENTIFIER : ('@')(ALPHA | '_')
+                              (ALPHA | DIGIT | '_' | '-' | '.')*;
     IDENTIFIER          : (ALPHA | '_')
                           (ALPHA | DIGIT | '_' | '-' | '.')*;
     STMTEND             : ';';
     DQUOTE              : '"';
     COLON               : ':';
+    COMMA               : ',';
+    EQUAL               : '=';
     PLUS : '+';
     MINUS: '-';