Andreas Huber | 1aec397 | 2016-08-26 09:26:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 17 | #include "Annotation.h" |
| 18 | |
| 19 | #include "Formatter.h" |
| 20 | |
| 21 | #include <vector> |
| 22 | |
| 23 | namespace android { |
| 24 | |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 25 | Annotation::Annotation(const char *name,AnnotationParamVector *params) |
| 26 | : mName(name), |
| 27 | mParamsByName(params) { |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | std::string Annotation::name() const { |
| 31 | return mName; |
| 32 | } |
| 33 | |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame] | 34 | const AnnotationParamVector &Annotation::params() const { |
| 35 | return *mParamsByName; |
| 36 | } |
| 37 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 38 | void Annotation::dump(Formatter &out) const { |
| 39 | out << "@" << mName; |
| 40 | |
| 41 | if (mParamsByName->size() == 0) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | out << "("; |
| 46 | |
| 47 | for (size_t i = 0; i < mParamsByName->size(); ++i) { |
| 48 | if (i > 0) { |
| 49 | out << ", "; |
| 50 | } |
| 51 | |
| 52 | out << mParamsByName->keyAt(i) << "="; |
| 53 | |
| 54 | const std::vector<std::string> *param = mParamsByName->valueAt(i); |
| 55 | if (param->size() > 1) { |
| 56 | out << "{"; |
| 57 | } |
| 58 | |
| 59 | bool first = true; |
| 60 | for (const auto &value : *param) { |
| 61 | if (!first) { |
| 62 | out << ", "; |
| 63 | } |
| 64 | |
| 65 | out << value; |
| 66 | |
| 67 | first = false; |
| 68 | } |
| 69 | |
| 70 | if (param->size() > 1) { |
| 71 | out << "}"; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | out << ")"; |
| 76 | } |
| 77 | |
| 78 | } // namespace android |
| 79 | |