blob: 2cf6495b4ec185df1f70da56068d9c6f98888582 [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
Zhuoyao Zhang5158db42016-08-10 10:25:20 -07009Annotation::Annotation(const char *name,AnnotationParamVector *params)
10 : mName(name),
11 mParamsByName(params) {
Andreas Huber3599d922016-08-09 10:42:57 -070012}
13
14std::string Annotation::name() const {
15 return mName;
16}
17
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070018const AnnotationParamVector &Annotation::params() const {
19 return *mParamsByName;
20}
21
Andreas Huber3599d922016-08-09 10:42:57 -070022void Annotation::dump(Formatter &out) const {
23 out << "@" << mName;
24
25 if (mParamsByName->size() == 0) {
26 return;
27 }
28
29 out << "(";
30
31 for (size_t i = 0; i < mParamsByName->size(); ++i) {
32 if (i > 0) {
33 out << ", ";
34 }
35
36 out << mParamsByName->keyAt(i) << "=";
37
38 const std::vector<std::string> *param = mParamsByName->valueAt(i);
39 if (param->size() > 1) {
40 out << "{";
41 }
42
43 bool first = true;
44 for (const auto &value : *param) {
45 if (!first) {
46 out << ", ";
47 }
48
49 out << value;
50
51 first = false;
52 }
53
54 if (param->size() > 1) {
55 out << "}";
56 }
57 }
58
59 out << ")";
60}
61
62} // namespace android
63