blob: b7f71bbdfa56210128445267c0449c6ec60300f9 [file] [log] [blame]
Andreas Huber1aec3972016-08-26 09:26:32 -07001/*
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 Huber3599d922016-08-09 10:42:57 -070017#include "Annotation.h"
18
19#include "Formatter.h"
20
21#include <vector>
22
23namespace android {
24
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070025Annotation::Annotation(const char *name,AnnotationParamVector *params)
26 : mName(name),
27 mParamsByName(params) {
Andreas Huber3599d922016-08-09 10:42:57 -070028}
29
30std::string Annotation::name() const {
31 return mName;
32}
33
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070034const AnnotationParamVector &Annotation::params() const {
35 return *mParamsByName;
36}
37
Andreas Huber3599d922016-08-09 10:42:57 -070038void 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