blob: 2e35341fc8e1551612f604a75ccad687798272b3 [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,
Iliyan Malchev639bff82016-08-13 14:24:11 -070012 bool oneway,
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070013 AnnotationVector *annotations)
Andreas Huberc9410c72016-07-28 12:18:40 -070014 : mName(name),
15 mArgs(args),
Andreas Huber3599d922016-08-09 10:42:57 -070016 mResults(results),
Iliyan Malchev639bff82016-08-13 14:24:11 -070017 mOneway(oneway),
Andreas Huber3599d922016-08-09 10:42:57 -070018 mAnnotationsByName(annotations) {
Andreas Huberc9410c72016-07-28 12:18:40 -070019}
20
Andreas Huber881227d2016-08-02 14:20:21 -070021std::string Method::name() const {
22 return mName;
23}
24
25const std::vector<TypedVar *> &Method::args() const {
26 return *mArgs;
27}
28
29const std::vector<TypedVar *> &Method::results() const {
30 return *mResults;
31}
32
Zhuoyao Zhang5158db42016-08-10 10:25:20 -070033const AnnotationVector &Method::annotations() const {
Andreas Huber3599d922016-08-09 10:42:57 -070034 return *mAnnotationsByName;
35}
36
Andreas Huber881227d2016-08-02 14:20:21 -070037// static
38std::string Method::GetSignature(const std::vector<TypedVar *> &args) {
39 bool first = true;
40 std::string out;
41 for (const auto &arg : args) {
42 if (!first) {
43 out += ", ";
44 }
45
46 std::string extra;
47 out += arg->type().getCppArgumentType(&extra);
48 out += " ";
49 out += arg->name();
50 out += extra;
51
52 first = false;
53 }
54
55 return out;
56}
57
Andreas Huber2831d512016-08-15 09:33:47 -070058// static
59std::string Method::GetJavaSignature(const std::vector<TypedVar *> &args) {
60 bool first = true;
61 std::string out;
62 for (const auto &arg : args) {
63 if (!first) {
64 out += ", ";
65 }
66
67 std::string extra;
68 out += arg->type().getJavaType();
69 out += " ";
70 out += arg->name();
71 out += extra;
72
73 first = false;
74 }
75
76 return out;
77}
78
Andreas Huber3599d922016-08-09 10:42:57 -070079void Method::dumpAnnotations(Formatter &out) const {
80 if (mAnnotationsByName->size() == 0) {
81 return;
82 }
83
84 out << "// ";
85 for (size_t i = 0; i < mAnnotationsByName->size(); ++i) {
86 if (i > 0) {
87 out << " ";
88 }
89 mAnnotationsByName->valueAt(i)->dump(out);
90 }
91 out << "\n";
92}
93
Andreas Huber70a59e12016-08-16 12:57:01 -070094bool Method::isJavaCompatible() const {
95 for (const auto &arg : *mArgs) {
96 if (!arg->isJavaCompatible()) {
97 return false;
98 }
99 }
100
101 for (const auto &result : *mResults) {
102 if (!result->isJavaCompatible()) {
103 return false;
104 }
105 }
106
107 return true;
108}
109
Andreas Huber31629bc2016-08-03 09:06:40 -0700110////////////////////////////////////////////////////////////////////////////////
111
112TypedVar::TypedVar(const char *name, Type *type)
113 : mName(name),
114 mType(type) {
115}
116
117std::string TypedVar::name() const {
118 return mName;
119}
120
121const Type &TypedVar::type() const {
122 return *mType;
123}
124
Andreas Huber70a59e12016-08-16 12:57:01 -0700125bool TypedVar::isJavaCompatible() const {
126 return mType->isJavaCompatible();
127}
128
Andreas Huberc9410c72016-07-28 12:18:40 -0700129} // namespace android
130