Interface methods can now be annotated.
The syntax is a strict subset of what Java supports. The following are valid
annotations:
@Fragile
@LotsOfStuff(single="yes", many={"a", "b", "c"})
An annotation either has no parameters (in which case the name is NOT followed
by parentheses) or is does and what follows the name is a parenthesized list
of name=value pairs, where each value is either a single quoted string literal
or a list of quoted string literals surrounded by curly braces.
Change-Id: I3c51d771b7d55c8d16531286d011f61be700a21c
diff --git a/Method.cpp b/Method.cpp
index 7e0058f..2569701 100644
--- a/Method.cpp
+++ b/Method.cpp
@@ -1,17 +1,19 @@
#include "Method.h"
+#include "Annotation.h"
#include "Formatter.h"
#include "Type.h"
namespace android {
-Method::Method(
- const char *name,
- std::vector<TypedVar *> *args,
- std::vector<TypedVar *> *results)
+Method::Method(const char *name,
+ std::vector<TypedVar *> *args,
+ std::vector<TypedVar *> *results,
+ KeyedVector<std::string, Annotation *> *annotations)
: mName(name),
mArgs(args),
- mResults(results) {
+ mResults(results),
+ mAnnotationsByName(annotations) {
}
std::string Method::name() const {
@@ -26,6 +28,10 @@
return *mResults;
}
+const KeyedVector<std::string, Annotation *> &Method::annotations() const {
+ return *mAnnotationsByName;
+}
+
// static
std::string Method::GetSignature(const std::vector<TypedVar *> &args) {
bool first = true;
@@ -47,6 +53,21 @@
return out;
}
+void Method::dumpAnnotations(Formatter &out) const {
+ if (mAnnotationsByName->size() == 0) {
+ return;
+ }
+
+ out << "// ";
+ for (size_t i = 0; i < mAnnotationsByName->size(); ++i) {
+ if (i > 0) {
+ out << " ";
+ }
+ mAnnotationsByName->valueAt(i)->dump(out);
+ }
+ out << "\n";
+}
+
////////////////////////////////////////////////////////////////////////////////
TypedVar::TypedVar(const char *name, Type *type)