Interface methods can now be annotated.

The syntax is a strict subset of what Java supports. The following are valid
annotations:

@Fragile
@LotsOfStuff(single="yes", many={"a", "b", "c"})

An annotation either has no parameters (in which case the name is NOT followed
by parentheses) or is does and what follows the name is a parenthesized list
of name=value pairs, where each value is either a single quoted string literal
or a list of quoted string literals surrounded by curly braces.

Change-Id: I3c51d771b7d55c8d16531286d011f61be700a21c
diff --git a/Annotation.cpp b/Annotation.cpp
new file mode 100644
index 0000000..d5692cf
--- /dev/null
+++ b/Annotation.cpp
@@ -0,0 +1,61 @@
+#include "Annotation.h"
+
+#include "Formatter.h"
+
+#include <vector>
+
+namespace android {
+
+Annotation::Annotation(
+        const char *name,
+        KeyedVector<std::string, std::vector<std::string> *> *params)
+    : mName(name),
+      mParamsByName(params) {
+}
+
+std::string Annotation::name() const {
+    return mName;
+}
+
+void Annotation::dump(Formatter &out) const {
+    out << "@" << mName;
+
+    if (mParamsByName->size() == 0) {
+        return;
+    }
+
+    out << "(";
+
+    for (size_t i = 0; i < mParamsByName->size(); ++i) {
+        if (i > 0) {
+            out << ", ";
+        }
+
+        out << mParamsByName->keyAt(i) << "=";
+
+        const std::vector<std::string> *param = mParamsByName->valueAt(i);
+        if (param->size() > 1) {
+            out << "{";
+        }
+
+        bool first = true;
+        for (const auto &value : *param) {
+            if (!first) {
+                out << ", ";
+            }
+
+            out << value;
+
+            first = false;
+        }
+
+        if (param->size() > 1) {
+            out << "}";
+        }
+    }
+
+    out << ")";
+}
+
+}  // namespace android
+