Skip to content

Commit

Permalink
THRIFT-5692 Support for deprecated methods (via annotation)
Browse files Browse the repository at this point in the history
Client: haxe
Patch: Jens Geyer
  • Loading branch information
Jens-G committed Mar 18, 2023
1 parent 0d95b8c commit 66aac44
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions compiler/cpp/src/thrift/generate/t_haxe_generator.cc
Expand Up @@ -209,6 +209,8 @@ class t_haxe_generator : public t_oop_generator {
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);
Expand Down Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down

0 comments on commit 66aac44

Please sign in to comment.