Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 1 | #include "Annotation.h" |
| 2 | |
| 3 | #include "Formatter.h" |
| 4 | |
| 5 | #include <vector> |
| 6 | |
| 7 | namespace android { |
| 8 | |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 9 | Annotation::Annotation(const char *name,AnnotationParamVector *params) |
| 10 | : mName(name), |
| 11 | mParamsByName(params) { |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 12 | } |
| 13 | |
| 14 | std::string Annotation::name() const { |
| 15 | return mName; |
| 16 | } |
| 17 | |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 18 | const AnnotationParamVector &Annotation::params() const { |
| 19 | return *mParamsByName; |
| 20 | } |
| 21 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 22 | void 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 | |