mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 18:58:51 +00:00
THRIFT-529. java: Change generated constructors so that application code evolves better
Optional fields are now excluded from constructors. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@820857 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f18202fbd0
commit
364902eb56
@ -1068,6 +1068,8 @@ void t_java_generator::generate_java_struct_definition(ofstream &out,
|
||||
|
||||
generate_java_meta_data_map(out, tstruct);
|
||||
|
||||
bool all_optional_members = true;
|
||||
|
||||
// Default constructor
|
||||
indent(out) <<
|
||||
"public " << tstruct->get_name() << "() {" << endl;
|
||||
@ -1077,22 +1079,27 @@ void t_java_generator::generate_java_struct_definition(ofstream &out,
|
||||
if ((*m_iter)->get_value() != NULL) {
|
||||
print_const_value(out, "this." + (*m_iter)->get_name(), t, (*m_iter)->get_value(), true, true);
|
||||
}
|
||||
if ((*m_iter)->get_req() != t_field::T_OPTIONAL) {
|
||||
all_optional_members = false;
|
||||
}
|
||||
}
|
||||
indent_down();
|
||||
indent(out) << "}" << endl << endl;
|
||||
|
||||
|
||||
if (!members.empty()) {
|
||||
if (!members.empty() && !all_optional_members) {
|
||||
// Full constructor for all fields
|
||||
indent(out) <<
|
||||
"public " << tstruct->get_name() << "(" << endl;
|
||||
indent_up();
|
||||
for (m_iter = members.begin(); m_iter != members.end(); ) {
|
||||
bool first = true;
|
||||
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
|
||||
if ((*m_iter)->get_req() != t_field::T_OPTIONAL) {
|
||||
if (!first) {
|
||||
out << "," << endl;
|
||||
}
|
||||
first = false;
|
||||
indent(out) << type_name((*m_iter)->get_type()) << " " <<
|
||||
(*m_iter)->get_name();
|
||||
++m_iter;
|
||||
if (m_iter != members.end()) {
|
||||
out << "," << endl;
|
||||
}
|
||||
}
|
||||
out << ")" << endl;
|
||||
@ -1101,10 +1108,12 @@ void t_java_generator::generate_java_struct_definition(ofstream &out,
|
||||
indent_up();
|
||||
indent(out) << "this();" << endl;
|
||||
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
|
||||
if ((*m_iter)->get_req() != t_field::T_OPTIONAL) {
|
||||
indent(out) << "this." << (*m_iter)->get_name() << " = " <<
|
||||
(*m_iter)->get_name() << ";" << endl;
|
||||
generate_isset_set(out, (*m_iter));
|
||||
}
|
||||
}
|
||||
indent_down();
|
||||
indent(out) << "}" << endl << endl;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user