summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Geyer <jensg@apache.org>2023-03-17 23:37:43 +0100
committerJens Geyer <Jens-G@users.noreply.github.com>2023-03-18 14:23:54 +0100
commit66aac4465926404c2bb0c450e80fac2c2824c04c (patch)
tree7decdcbecff8b7372711ab0fc2a34fa9ebd872e8
parent0d95b8c4e1d5be3ae4cc3fe5823cddbb91dbc2ec (diff)
downloadthrift-66aac4465926404c2bb0c450e80fac2c2824c04c.tar.gz
THRIFT-5692 Support for deprecated methods (via annotation)
Client: haxe Patch: Jens Geyer
-rw-r--r--compiler/cpp/src/thrift/generate/t_haxe_generator.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/compiler/cpp/src/thrift/generate/t_haxe_generator.cc b/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
index aa628b7ab..9397ff15f 100644
--- a/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
@@ -209,6 +209,8 @@ public:
string generate_service_method_onsuccess(t_function* tfunction, bool as_type, bool omit_name);
void generate_service_method_signature_combined(t_function* tfunction, bool is_interface);
void generate_service_method_signature_normal(t_function* tfunction, bool is_interface);
+ void generate_deprecation_attribute(ostream& out, t_function* func, bool as_comment);
+ string make_haxe_string_literal( string const& value);
bool type_can_be_null(t_type* ttype) {
ttype = get_true_type(ttype);
@@ -1664,6 +1666,7 @@ void t_haxe_generator::generate_service_method_signature(t_function* tfunction,
void t_haxe_generator::generate_service_method_signature_normal(t_function* tfunction,
bool is_interface) {
if (is_interface) {
+ generate_deprecation_attribute(f_service_, tfunction, true);
indent(f_service_) << function_signature_normal(tfunction) << ";" << endl << endl;
} else {
indent(f_service_) << "public " << function_signature_normal(tfunction) << " {" << endl;
@@ -1684,12 +1687,60 @@ void t_haxe_generator::generate_service_method_signature_combined(t_function* tf
}
if (is_interface) {
+ generate_deprecation_attribute(f_service_, tfunction, false);
indent(f_service_) << function_signature_combined(tfunction) << ";" << endl << endl;
} else {
indent(f_service_) << "public " << function_signature_combined(tfunction) << " {" << endl;
}
}
+string t_haxe_generator::make_haxe_string_literal( string const& value)
+{
+ if (value.length() == 0) {
+ return "";
+ }
+
+ std::stringstream result;
+ result << "\"";
+ for (signed char const c: value) {
+ if( (c >= 0) && (c < 32)) { // convert ctrl chars, but leave UTF-8 alone
+ int width = std::min( (int)sizeof(c), 6);
+ result << "\\u{" << std::hex << std::setw(width) << std::setfill('0') << (int)c << '}';
+ } else if ((c == '\\') || (c == '"')) {
+ result << "\\" << c;
+ } else {
+ result << c; // anything else "as is"
+ }
+ }
+ result << "\"";
+
+ return result.str();
+}
+
+void t_haxe_generator::generate_deprecation_attribute(ostream& out, t_function* func, bool as_comment)
+{
+ auto iter = func->annotations_.find("deprecated");
+ if( func->annotations_.end() != iter) {
+ if( as_comment) {
+ out << indent() << "// DEPRECATED";
+ } else {
+ out << indent() << "@:deprecated";
+ }
+
+ // empty annotation values end up with "1" somewhere, ignore these as well
+ if ((iter->second.back().length() > 0) && (iter->second.back() != "1")) {
+ string text = make_haxe_string_literal(iter->second.back());
+ if( as_comment) {
+ out << ": " << text;
+ } else {
+ out << "(" << text << ")";
+ }
+ }
+
+ out << endl;
+ }
+}
+
/**
* Generates a service interface definition.
*