Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 1 | #include "Method.h" |
| 2 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 3 | #include "Annotation.h" |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 4 | #include "Formatter.h" |
| 5 | #include "Type.h" |
| 6 | |
| 7 | namespace android { |
| 8 | |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 9 | Method::Method(const char *name, |
| 10 | std::vector<TypedVar *> *args, |
| 11 | std::vector<TypedVar *> *results, |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame^] | 12 | AnnotationVector *annotations) |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 13 | : mName(name), |
| 14 | mArgs(args), |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 15 | mResults(results), |
| 16 | mAnnotationsByName(annotations) { |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 17 | } |
| 18 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 19 | std::string Method::name() const { |
| 20 | return mName; |
| 21 | } |
| 22 | |
| 23 | const std::vector<TypedVar *> &Method::args() const { |
| 24 | return *mArgs; |
| 25 | } |
| 26 | |
| 27 | const std::vector<TypedVar *> &Method::results() const { |
| 28 | return *mResults; |
| 29 | } |
| 30 | |
Zhuoyao Zhang | 5158db4 | 2016-08-10 10:25:20 -0700 | [diff] [blame^] | 31 | const AnnotationVector &Method::annotations() const { |
Andreas Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 32 | return *mAnnotationsByName; |
| 33 | } |
| 34 | |
Andreas Huber | 881227d | 2016-08-02 14:20:21 -0700 | [diff] [blame] | 35 | // static |
| 36 | std::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 Huber | 2831d51 | 2016-08-15 09:33:47 -0700 | [diff] [blame] | 56 | // static |
| 57 | std::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 Huber | 3599d92 | 2016-08-09 10:42:57 -0700 | [diff] [blame] | 77 | void 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 Huber | 31629bc | 2016-08-03 09:06:40 -0700 | [diff] [blame] | 92 | //////////////////////////////////////////////////////////////////////////////// |
| 93 | |
| 94 | TypedVar::TypedVar(const char *name, Type *type) |
| 95 | : mName(name), |
| 96 | mType(type) { |
| 97 | } |
| 98 | |
| 99 | std::string TypedVar::name() const { |
| 100 | return mName; |
| 101 | } |
| 102 | |
| 103 | const Type &TypedVar::type() const { |
| 104 | return *mType; |
| 105 | } |
| 106 | |
Andreas Huber | c9410c7 | 2016-07-28 12:18:40 -0700 | [diff] [blame] | 107 | } // namespace android |
| 108 | |