summaryrefslogtreecommitdiff
path: root/tools/aapt2/java/AnnotationProcessor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aapt2/java/AnnotationProcessor.cpp')
-rw-r--r--tools/aapt2/java/AnnotationProcessor.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/tools/aapt2/java/AnnotationProcessor.cpp b/tools/aapt2/java/AnnotationProcessor.cpp
index bb667d6fa539..482d91aeb491 100644
--- a/tools/aapt2/java/AnnotationProcessor.cpp
+++ b/tools/aapt2/java/AnnotationProcessor.cpp
@@ -18,6 +18,7 @@
#include <algorithm>
#include <array>
+#include <regex>
#include "text/Unicode.h"
#include "text/Utf8Iterator.h"
@@ -65,14 +66,26 @@ void AnnotationProcessor::AppendCommentLine(std::string comment) {
// Treat deprecated specially, since we don't remove it from the source comment.
if (comment.find(sDeprecated) != std::string::npos) {
- annotation_bit_mask_ |= AnnotationRule::kDeprecated;
+ annotation_parameter_map_[AnnotationRule::kDeprecated] = "";
}
for (const AnnotationRule& rule : sAnnotationRules) {
std::string::size_type idx = comment.find(rule.doc_str.data());
if (idx != std::string::npos) {
- annotation_bit_mask_ |= rule.bit_mask;
- comment.erase(comment.begin() + idx, comment.begin() + idx + rule.doc_str.size());
+ // Captures all parameters associated with the specified annotation rule
+ // by matching the first pair of parantheses after the rule.
+ std::regex re(rule.doc_str.to_string() + "\\s*\\((.+)\\)");
+ std::smatch match_result;
+ const bool is_match = std::regex_search(comment, match_result, re);
+ // We currently only capture and preserve parameters for SystemApi.
+ if (is_match && rule.bit_mask == AnnotationRule::kSystemApi) {
+ annotation_parameter_map_[rule.bit_mask] = match_result[1].str();
+ comment.erase(comment.begin() + match_result.position(),
+ comment.begin() + match_result.position() + match_result.length());
+ } else {
+ annotation_parameter_map_[rule.bit_mask] = "";
+ comment.erase(comment.begin() + idx, comment.begin() + idx + rule.doc_str.size());
+ }
}
}
@@ -119,7 +132,8 @@ void AnnotationProcessor::Print(Printer* printer, bool strip_api_annotations) co
printer->Println(" */");
}
- if (annotation_bit_mask_ & AnnotationRule::kDeprecated) {
+ if (annotation_parameter_map_.find(AnnotationRule::kDeprecated) !=
+ annotation_parameter_map_.end()) {
printer->Println("@Deprecated");
}
@@ -127,8 +141,13 @@ void AnnotationProcessor::Print(Printer* printer, bool strip_api_annotations) co
return;
}
for (const AnnotationRule& rule : sAnnotationRules) {
- if (annotation_bit_mask_ & rule.bit_mask) {
- printer->Println(rule.annotation);
+ const auto& it = annotation_parameter_map_.find(rule.bit_mask);
+ if (it != annotation_parameter_map_.end()) {
+ printer->Print(rule.annotation);
+ if (!it->second.empty()) {
+ printer->Print("(").Print(it->second).Print(")");
+ }
+ printer->Print("\n");
}
}
}