Support annotation for interface in hidl-gen.

Change-Id: I8b59695dad33473202b490ef0cb4bb928019b8ee
diff --git a/Interface.cpp b/Interface.cpp
index 158f874..451aca3 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -1,12 +1,16 @@
 #include "Interface.h"
 
+#include "Annotation.h"
 #include "Formatter.h"
 #include "Method.h"
 
 namespace android {
 
-Interface::Interface(Interface *super)
-    : mSuperType(super) {
+Interface::Interface(
+        Interface *super,
+        KeyedVector<std::string, Annotation *> *annotations)
+        : mSuperType(super),
+          mAnnotationsByName(annotations) {
 }
 
 void Interface::addMethod(Method *method) {
@@ -25,6 +29,10 @@
     return mMethods;
 }
 
+const KeyedVector<std::string, Annotation *> &Interface::annotations() const {
+    return *mAnnotationsByName;
+}
+
 std::string Interface::getCppType(StorageMode mode, std::string *extra) const {
     extra->clear();
     const std::string base = "::android::sp<" + fullName() + ">";
diff --git a/Interface.h b/Interface.h
index 7ad0d6d..d7bf0a3 100644
--- a/Interface.h
+++ b/Interface.h
@@ -4,14 +4,18 @@
 
 #include "Scope.h"
 
+#include <utils/KeyedVector.h>
 #include <vector>
 
 namespace android {
 
+struct Annotation;
 struct Method;
 
 struct Interface : public Scope {
-    Interface(Interface *super);
+    Interface(
+            Interface *super,
+            KeyedVector<std::string, Annotation *> *annotations);
 
     void addMethod(Method *method);
 
@@ -21,6 +25,8 @@
 
     const std::vector<Method *> &methods() const;
 
+    const KeyedVector<std::string, Annotation *> &annotations() const;
+
     std::string getCppType(StorageMode mode, std::string *extra) const override;
 
     void emitReaderWriter(
@@ -34,6 +40,7 @@
 private:
     Interface *mSuperType;
     std::vector<Method *> mMethods;
+    KeyedVector<std::string, Annotation *> *mAnnotationsByName;
 
     DISALLOW_COPY_AND_ASSIGN(Interface);
 };
diff --git a/hidl-gen_y.yy b/hidl-gen_y.yy
index 0b1cd90..7fec3b8 100644
--- a/hidl-gen_y.yy
+++ b/hidl-gen_y.yy
@@ -237,18 +237,18 @@
     | EXTENDS fqname { $$ = $2; }
 
 body
-    : INTERFACE IDENTIFIER opt_extends
+    : opt_annotations INTERFACE IDENTIFIER opt_extends
       {
-          if ($3 != NULL && !$3->isInterface()) {
+          if ($4 != NULL && !$4->isInterface()) {
               fprintf(stderr, "You can only extend interfaces.\n");
               YYERROR;
           }
 
-          Interface *iface = new Interface(static_cast<Interface *>($3));
+          Interface *iface = new Interface(static_cast<Interface *>($4), $1);
 
           // Register interface immediately so it can be referenced inside
           // definition.
-          if (!ast->addScopedType($2, iface)) {
+          if (!ast->addScopedType($3, iface)) {
               YYERROR;
           }