blob: 37c71ea6cdddc619b3210662062fad67daa02990 [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,
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070012 AnnotationVector *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
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070031const AnnotationVector &Method::annotations() const {
Andreas Huber3599d922016-08-09 10:42:57 -070032 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 Huber2831d512016-08-15 09:33:47 -070056// static
57std::string Method::GetJavaSignature(const std::vector<TypedVar *> &args) {
58 bool first = true;
59 std::string out;
60 for (const auto &arg : args) {
61 if (!first) {
62 out += ", ";
63 }
64
65 std::string extra;
66 out += arg->type().getJavaType();
67 out += " ";
68 out += arg->name();
69 out += extra;
70
71 first = false;
72 }
73
74 return out;
75}
76
Andreas Huber3599d922016-08-09 10:42:57 -070077void Method::dumpAnnotations(Formatter &out) const {
78 if (mAnnotationsByName->size() == 0) {
79 return;
80 }
81
82 out << "// ";
83 for (size_t i = 0; i < mAnnotationsByName->size(); ++i) {
84 if (i > 0) {
85 out << " ";
86 }
87 mAnnotationsByName->valueAt(i)->dump(out);
88 }
89 out << "\n";
90}
91
Andreas Huber31629bc2016-08-03 09:06:40 -070092////////////////////////////////////////////////////////////////////////////////
93
94TypedVar::TypedVar(const char *name, Type *type)
95 : mName(name),
96 mType(type) {
97}
98
99std::string TypedVar::name() const {
100 return mName;
101}
102
103const Type &TypedVar::type() const {
104 return *mType;
105}
106
Andreas Huberc9410c72016-07-28 12:18:40 -0700107} // namespace android
108