blob: d5692cf93a6ac32b7219504437e74d53c34a835c [file] [log] [blame]
Andreas Huber3599d922016-08-09 10:42:57 -07001#include "Annotation.h"
2
3#include "Formatter.h"
4
5#include <vector>
6
7namespace android {
8
9Annotation::Annotation(
10 const char *name,
11 KeyedVector<std::string, std::vector<std::string> *> *params)
12 : mName(name),
13 mParamsByName(params) {
14}
15
16std::string Annotation::name() const {
17 return mName;
18}
19
20void Annotation::dump(Formatter &out) const {
21 out << "@" << mName;
22
23 if (mParamsByName->size() == 0) {
24 return;
25 }
26
27 out << "(";
28
29 for (size_t i = 0; i < mParamsByName->size(); ++i) {
30 if (i > 0) {
31 out << ", ";
32 }
33
34 out << mParamsByName->keyAt(i) << "=";
35
36 const std::vector<std::string> *param = mParamsByName->valueAt(i);
37 if (param->size() > 1) {
38 out << "{";
39 }
40
41 bool first = true;
42 for (const auto &value : *param) {
43 if (!first) {
44 out << ", ";
45 }
46
47 out << value;
48
49 first = false;
50 }
51
52 if (param->size() > 1) {
53 out << "}";
54 }
55 }
56
57 out << ")";
58}
59
60} // namespace android
61