THRIFT-2629 JavaDoc style documentation should be reused

Client: C++
This commit is contained in:
henrique 2014-07-16 22:03:16 +02:00
parent a75a5f0f70
commit 7a8b286b3f
3 changed files with 99 additions and 109 deletions

View File

@ -874,7 +874,7 @@ void t_cpp_generator::generate_assignment_operator(
}
/**
* Writes the struct definition into the header file
* Writes the struct declaration into the header file
*
* @param out Output stream
* @param tstruct The struct
@ -1041,14 +1041,14 @@ void t_cpp_generator::generate_struct_declaration(ofstream& out,
}
if (is_reference((*m_iter))) {
out <<
endl <<
indent() << "void __set_" << (*m_iter)->get_name() <<
endl <<
indent() << "void __set_" << (*m_iter)->get_name() <<
"(boost::shared_ptr<" << type_name((*m_iter)->get_type(), false, false) << ">";
out << " val);" << endl;
} else {
out <<
endl <<
indent() << "void __set_" << (*m_iter)->get_name() <<
endl <<
indent() << "void __set_" << (*m_iter)->get_name() <<
"(" << type_name((*m_iter)->get_type(), false, true);
out << " val);" << endl;
}
@ -1162,17 +1162,17 @@ void t_cpp_generator::generate_struct_definition(ofstream& out,
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
if (is_reference((*m_iter))) {
std::string type = type_name((*m_iter)->get_type());
out <<
endl <<
indent() << "void " << tstruct->get_name() << "::__set_" << (*m_iter)->get_name() <<
"(boost::shared_ptr<" << type_name((*m_iter)->get_type(), false, false) << ">";
out << " val) {" << endl;
out <<
endl <<
indent() << "void " << tstruct->get_name() << "::__set_" << (*m_iter)->get_name() <<
"(boost::shared_ptr<" << type_name((*m_iter)->get_type(), false, false) << ">";
out << " val) {" << endl;
} else {
out <<
endl <<
indent() << "void " << tstruct->get_name() << "::__set_" << (*m_iter)->get_name() <<
"(" << type_name((*m_iter)->get_type(), false, true);
out << " val) {" << endl;
out <<
endl <<
indent() << "void " << tstruct->get_name() << "::__set_" << (*m_iter)->get_name() <<
"(" << type_name((*m_iter)->get_type(), false, true);
out << " val) {" << endl;
}
indent_up();
out << indent() << "this->" << (*m_iter)->get_name() << " = val;" << endl;
@ -1945,6 +1945,8 @@ void t_cpp_generator::generate_service_interface(t_service* tservice, string sty
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::iterator f_iter;
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
if ((*f_iter)->has_doc()) f_header_ << endl;
generate_java_doc(f_header_, *f_iter);
f_header_ <<
indent() << "virtual " << function_signature(*f_iter, style) << " = 0;" << endl;
}
@ -3956,6 +3958,7 @@ void t_cpp_generator::generate_service_skeleton(t_service* tservice) {
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::iterator f_iter;
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
generate_java_doc(f_skeleton, *f_iter);
f_skeleton <<
indent() << function_signature(*f_iter, "") << " {" << endl <<
indent() << " // Your implementation goes here" << endl <<

View File

@ -248,18 +248,6 @@ public:
std::string iter,
bool has_metadata = true);
void generate_java_doc (std::ofstream& out,
t_field* field);
void generate_java_doc (std::ofstream& out,
t_doc* tdoc);
void generate_java_doc (std::ofstream& out,
t_function* tdoc);
void generate_java_docstring_comment (std::ofstream &out,
string contents);
void generate_deep_copy_container(std::ofstream& out, std::string source_name_p1, std::string source_name_p2, std::string result_name, t_type* type);
void generate_deep_copy_non_container(std::ofstream& out, std::string source_name, std::string dest_name, t_type* type);
@ -282,7 +270,6 @@ public:
std::string async_function_call_arglist(t_function* tfunc, bool use_base_method = true, bool include_types = true);
std::string async_argument_list(t_function* tfunct, t_struct* tstruct, t_type* ttype, bool include_types=false);
std::string type_to_enum(t_type* ttype);
std::string get_enum_class_name(t_type* type);
void generate_struct_desc(ofstream& out, t_struct* tstruct);
void generate_field_descs(ofstream& out, t_struct* tstruct);
void generate_field_name_constants(ofstream& out, t_struct* tstruct);
@ -1680,7 +1667,7 @@ void t_java_generator::generate_java_struct_reader(ofstream& out,
indent(out) << "schemes.get(iprot.getScheme()).getScheme().read(iprot, this);" << endl;
indent_down();
indent(out) << "}" << endl <<
endl;
endl;
}
// generates java method to perform various checks
@ -1740,7 +1727,7 @@ void t_java_generator::generate_java_struct_writer(ofstream& out,
indent(out) << "schemes.get(oprot.getScheme()).getScheme().write(oprot, this);" << endl;
indent_down();
indent(out) << "}" << endl << endl;
indent(out) << "}" << endl << endl;
}
/**
@ -1759,7 +1746,7 @@ void t_java_generator::generate_java_struct_result_writer(ofstream& out,
indent(out) << "schemes.get(oprot.getScheme()).getScheme().write(oprot, this);" << endl;
indent_down();
indent(out) << " }" << endl << endl;
indent(out) << " }" << endl << endl;
}
void t_java_generator::generate_java_struct_field_by_id(ofstream& out, t_struct* tstruct) {
@ -2809,18 +2796,18 @@ void t_java_generator::generate_process_async_function(t_service* tservice,
indent(f_service_) << "final org.apache.thrift.AsyncProcessFunction fcall = this;"<<endl;
indent(f_service_) << "return new AsyncMethodCallback<"<<resulttype<<">() { " << endl;
indent_up();
indent(f_service_) << "public void onComplete(" << resulttype <<" o) {" << endl;
indent(f_service_) << "public void onComplete(" << resulttype <<" o) {" << endl;
indent_up();
if (!tfunction->is_oneway()) {
indent(f_service_) <<resultname<<" result = new "<<resultname<<"();"<<endl;
if (!tfunction->get_returntype()->is_void()) {
indent(f_service_) << "result.success = o;"<<endl;
indent(f_service_) << "result.success = o;"<<endl;
// Set isset on success field
if (!type_can_be_null(tfunction->get_returntype())) {
indent(f_service_) << "result.set" << get_cap_name("success") << get_cap_name("isSet") << "(true);" << endl;
}
if (!type_can_be_null(tfunction->get_returntype())) {
indent(f_service_) << "result.set" << get_cap_name("success") << get_cap_name("isSet") << "(true);" << endl;
}
}
indent(f_service_) << "try {"<<endl;
@ -2840,24 +2827,24 @@ void t_java_generator::generate_process_async_function(t_service* tservice,
if (!tfunction->is_oneway()) {
indent(f_service_) <<"byte msgType = org.apache.thrift.protocol.TMessageType.REPLY;"<<endl;
indent(f_service_) <<"org.apache.thrift.TBase msg;"<<endl;
indent(f_service_) <<"byte msgType = org.apache.thrift.protocol.TMessageType.REPLY;"<<endl;
indent(f_service_) <<"org.apache.thrift.TBase msg;"<<endl;
indent(f_service_) <<resultname<<" result = new "<<resultname<<"();"<<endl;
t_struct* xs = tfunction->get_xceptions();
const std::vector<t_field*>& xceptions = xs->get_members();
vector<t_field*>::const_iterator x_iter;
if (xceptions.size() > 0) {
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
if (x_iter != xceptions.begin()) indent(f_service_) << "else ";
indent(f_service_) << "if (e instanceof " << type_name((*x_iter)->get_type(), false, false)<<") {" << endl;
indent(f_service_) << indent() << "result." << (*x_iter)->get_name() << " = (" << type_name((*x_iter)->get_type(), false, false) << ") e;" << endl;
indent(f_service_) << indent() << "result.set" << get_cap_name((*x_iter)->get_name()) << get_cap_name("isSet") << "(true);" << endl;
indent(f_service_) << indent() << "msg = result;"<<endl;
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
if (x_iter != xceptions.begin()) indent(f_service_) << "else ";
indent(f_service_) << "if (e instanceof " << type_name((*x_iter)->get_type(), false, false)<<") {" << endl;
indent(f_service_) << indent() << "result." << (*x_iter)->get_name() << " = (" << type_name((*x_iter)->get_type(), false, false) << ") e;" << endl;
indent(f_service_) << indent() << "result.set" << get_cap_name((*x_iter)->get_name()) << get_cap_name("isSet") << "(true);" << endl;
indent(f_service_) << indent() << "msg = result;"<<endl;
indent(f_service_) << "}"<<endl;
}
indent(f_service_) << " else "<<endl;
indent(f_service_) << "}"<<endl;
}
indent(f_service_) << " else "<<endl;
}
indent(f_service_) << "{"<<endl;
@ -2907,7 +2894,7 @@ void t_java_generator::generate_process_async_function(t_service* tservice,
f_service_ << "args." << (*f_iter)->get_name();
}
if (!first)
f_service_ << ",";
f_service_ << ",";
f_service_ << "resultHandler";
f_service_ << ");" << endl;
@ -3889,57 +3876,6 @@ string t_java_generator::constant_name(string name) {
return constant_name;
}
void t_java_generator::generate_java_docstring_comment(ofstream &out, string contents) {
generate_docstring_comment(out,
"/**\n",
" * ", contents,
" */\n");
}
void t_java_generator::generate_java_doc(ofstream &out,
t_field* field) {
if (field->get_type()->is_enum()) {
string combined_message = field->get_doc() + "\n@see " + get_enum_class_name(field->get_type());
generate_java_docstring_comment(out, combined_message);
} else {
generate_java_doc(out, (t_doc*)field);
}
}
/**
* Emits a JavaDoc comment if the provided object has a doc in Thrift
*/
void t_java_generator::generate_java_doc(ofstream &out,
t_doc* tdoc) {
if (tdoc->has_doc()) {
generate_java_docstring_comment(out, tdoc->get_doc());
}
}
/**
* Emits a JavaDoc comment if the provided function object has a doc in Thrift
*/
void t_java_generator::generate_java_doc(ofstream &out,
t_function* tfunction) {
if (tfunction->has_doc()) {
stringstream ss;
ss << tfunction->get_doc();
const vector<t_field*>& fields = tfunction->get_arglist()->get_members();
vector<t_field*>::const_iterator p_iter;
for (p_iter = fields.begin(); p_iter != fields.end(); ++p_iter) {
t_field* p = *p_iter;
ss << "\n@param " << p->get_name();
if (p->has_doc()) {
ss << " " << p->get_doc();
}
}
generate_docstring_comment(out,
"/**\n",
" * ", ss.str(),
" */\n");
}
}
void t_java_generator::generate_deep_copy_container(ofstream &out, std::string source_name_p1, std::string source_name_p2,
std::string result_name, t_type* type) {
@ -4087,15 +4023,6 @@ void t_java_generator::generate_isset_set(ofstream& out, t_field* field, string
}
}
std::string t_java_generator::get_enum_class_name(t_type* type) {
string package = "";
t_program* program = type->get_program();
if (program != NULL && program != program_) {
package = program->get_namespace("java") + ".";
}
return package + type->get_name();
}
void t_java_generator::generate_struct_desc(ofstream& out, t_struct* tstruct) {
indent(out) <<
"private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct(\"" << tstruct->get_name() << "\");" << endl;
@ -4412,7 +4339,7 @@ void t_java_generator::generate_standard_reader(ofstream& out, t_struct* tstruct
indent(out) << "struct.validate();" << endl;
indent_down();
out << indent() << "}" << endl;
out << indent() << "}" << endl;
}
void t_java_generator::generate_standard_writer(ofstream& out, t_struct* tstruct, bool is_result) {

View File

@ -78,6 +78,66 @@ class t_oop_generator : public t_generator {
return
std::string("Autogenerated by Thrift Compiler (") + THRIFT_VERSION + ")";
}
virtual std::string get_enum_class_name(t_type* type) {
std::string package = "";
t_program* program = type->get_program();
if (program != NULL && program != program_) {
package = program->get_namespace("java") + ".";
}
return package + type->get_name();
}
virtual void generate_java_docstring_comment(std::ofstream &out, std::string contents) {
generate_docstring_comment(out,
"/**\n",
" * ", contents,
" */\n");
}
virtual void generate_java_doc(std::ofstream &out,
t_field* field) {
if (field->get_type()->is_enum()) {
std::string combined_message = field->get_doc() + "\n@see " + get_enum_class_name(field->get_type());
generate_java_docstring_comment(out, combined_message);
} else {
generate_java_doc(out, (t_doc*)field);
}
}
/**
* Emits a JavaDoc comment if the provided object has a doc in Thrift
*/
virtual void generate_java_doc(std::ofstream &out,
t_doc* tdoc) {
if (tdoc->has_doc()) {
generate_java_docstring_comment(out, tdoc->get_doc());
}
}
/**
* Emits a JavaDoc comment if the provided function object has a doc in Thrift
*/
virtual void generate_java_doc(std::ofstream &out,
t_function* tfunction) {
if (tfunction->has_doc()) {
std::stringstream ss;
ss << tfunction->get_doc();
const std::vector<t_field*>& fields = tfunction->get_arglist()->get_members();
std::vector<t_field*>::const_iterator p_iter;
for (p_iter = fields.begin(); p_iter != fields.end(); ++p_iter) {
t_field* p = *p_iter;
ss << "\n@param " << p->get_name();
if (p->has_doc()) {
ss << " " << p->get_doc();
}
}
generate_docstring_comment(out,
"/**\n",
" * ", ss.str(),
" */\n");
}
}
};
#endif