blob: 256970152714aeb8dea4bfcd2638f5da08d139f5 [file] [log] [blame]
Andreas Huberc9410c72016-07-28 12:18:40 -07001#include "Method.h"
2
Andreas Huber3599d922016-08-09 10:42:57 -07003#include "Annotation.h"
Andreas Huberc9410c72016-07-28 12:18:40 -07004#include "Formatter.h"
5#include "Type.h"
6
7namespace android {
8
Andreas Huber3599d922016-08-09 10:42:57 -07009Method::Method(const char *name,
10 std::vector<TypedVar *> *args,
11 std::vector<TypedVar *> *results,
12 KeyedVector<std::string, Annotation *> *annotations)
Andreas Huberc9410c72016-07-28 12:18:40 -070013 : mName(name),
14 mArgs(args),
Andreas Huber3599d922016-08-09 10:42:57 -070015 mResults(results),
16 mAnnotationsByName(annotations) {
Andreas Huberc9410c72016-07-28 12:18:40 -070017}
18
Andreas Huber881227d2016-08-02 14:20:21 -070019std::string Method::name() const {
20 return mName;
21}
22
23const std::vector<TypedVar *> &Method::args() const {
24 return *mArgs;
25}
26
27const std::vector<TypedVar *> &Method::results() const {
28 return *mResults;
29}
30
Andreas Huber3599d922016-08-09 10:42:57 -070031const KeyedVector<std::string, Annotation *> &Method::annotations() const {
32 return *mAnnotationsByName;
33}
34
Andreas Huber881227d2016-08-02 14:20:21 -070035// static
36std::string Method::GetSignature(const std::vector<TypedVar *> &args) {
37 bool first = true;
38 std::string out;
39 for (const auto &arg : args) {
40 if (!first) {
41 out += ", ";
42 }
43
44 std::string extra;
45 out += arg->type().getCppArgumentType(&extra);
46 out += " ";
47 out += arg->name();
48 out += extra;
49
50 first = false;
51 }
52
53 return out;
54}
55
Andreas Huber3599d922016-08-09 10:42:57 -070056void Method::dumpAnnotations(Formatter &out) const {
57 if (mAnnotationsByName->size() == 0) {
58 return;
59 }
60
61 out << "// ";
62 for (size_t i = 0; i < mAnnotationsByName->size(); ++i) {
63 if (i > 0) {
64 out << " ";
65 }
66 mAnnotationsByName->valueAt(i)->dump(out);
67 }
68 out << "\n";
69}
70
Andreas Huber31629bc2016-08-03 09:06:40 -070071////////////////////////////////////////////////////////////////////////////////
72
73TypedVar::TypedVar(const char *name, Type *type)
74 : mName(name),
75 mType(type) {
76}
77
78std::string TypedVar::name() const {
79 return mName;
80}
81
82const Type &TypedVar::type() const {
83 return *mType;
84}
85
Andreas Huberc9410c72016-07-28 12:18:40 -070086} // namespace android
87