THRIFT-157. rb: Quote strings and qualify class names properly
Author: Dave Engberg
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@731763 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc
index 4d90b10..b2fc5bc 100644
--- a/compiler/cpp/src/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/generate/t_rb_generator.cc
@@ -147,6 +147,7 @@
std::string render_includes();
std::string declare_field(t_field* tfield);
std::string type_name(t_type* ttype);
+ std::string full_type_name(t_type* ttype);
std::string function_signature(t_function* tfunction, std::string prefix="");
std::string argument_list(t_struct* tstruct);
std::string type_to_enum(t_type* ttype);
@@ -328,7 +329,7 @@
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
switch (tbase) {
case t_base_type::TYPE_STRING:
- out << "'" << value->get_string() << "'";
+ out << "%q\"" << value->get_string() << '"';
break;
case t_base_type::TYPE_BOOL:
out << (value->get_integer() > 0 ? "true" : "false");
@@ -559,7 +560,7 @@
if (!field_type->is_base_type()) {
if (field_type->is_struct() || field_type->is_xception()) {
- out << ", :class => " << type_name(((t_struct*)field_type));
+ out << ", :class => " << full_type_name((t_struct*)field_type);
} else if (field_type->is_list()) {
out << ", :element => ";
generate_field_data(out, ((t_list*)field_type)->get_elem_type());
@@ -905,7 +906,7 @@
indent_down();
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
f_service_ <<
- indent() << "rescue " << (*x_iter)->get_type()->get_name() << " => " << (*x_iter)->get_name() << endl;
+ indent() << "rescue " << full_type_name((*x_iter)->get_type()) << " => " << (*x_iter)->get_name() << endl;
if (!tfunction->is_async()) {
indent_up();
f_service_ <<
@@ -978,6 +979,16 @@
return prefix + name;
}
+string t_rb_generator::full_type_name(t_type* ttype) {
+ string prefix = "";
+ vector<std::string> modules = ruby_modules(ttype->get_program());
+ for (vector<std::string>::iterator m_iter = modules.begin();
+ m_iter != modules.end(); ++m_iter) {
+ prefix += *m_iter + "::";
+ }
+ return prefix + type_name(ttype);
+}
+
/**
* Converts the parse type to a Ruby tyoe
*/
diff --git a/lib/rb/spec/gen-rb/NonblockingService.rb b/lib/rb/spec/gen-rb/NonblockingService.rb
index a886805..8044d8e 100644
--- a/lib/rb/spec/gen-rb/NonblockingService.rb
+++ b/lib/rb/spec/gen-rb/NonblockingService.rb
@@ -132,7 +132,7 @@
Thrift::Struct.field_accessor self, :success
FIELDS = {
- SUCCESS => {:type => Thrift::Types::STRUCT, :name => 'success', :class => Hello}
+ SUCCESS => {:type => Thrift::Types::STRUCT, :name => 'success', :class => SpecNamespace::Hello}
}
def validate
end
diff --git a/lib/rb/spec/gen-rb/ThriftSpec_types.rb b/lib/rb/spec/gen-rb/ThriftSpec_types.rb
index 613c8de..a28c921 100644
--- a/lib/rb/spec/gen-rb/ThriftSpec_types.rb
+++ b/lib/rb/spec/gen-rb/ThriftSpec_types.rb
@@ -13,7 +13,7 @@
Thrift::Struct.field_accessor self, :greeting
FIELDS = {
- GREETING => {:type => Thrift::Types::STRING, :name => 'greeting', :default => 'hello world'}
+ GREETING => {:type => Thrift::Types::STRING, :name => 'greeting', :default => %q"hello world"}
}
def validate
end
@@ -33,10 +33,10 @@
Thrift::Struct.field_accessor self, :simple, :words, :hello, :ints, :complex, :shorts, :opt_string
FIELDS = {
SIMPLE => {:type => Thrift::Types::I32, :name => 'simple', :default => 53},
- WORDS => {:type => Thrift::Types::STRING, :name => 'words', :default => 'words'},
+ WORDS => {:type => Thrift::Types::STRING, :name => 'words', :default => %q"words"},
HELLO => {:type => Thrift::Types::STRUCT, :name => 'hello', :default => Hello.new({
- 'greeting' => 'hello, world!',
- }), :class => Hello},
+ %q"greeting" => %q"hello, world!",
+ }), :class => SpecNamespace::Hello},
INTS => {:type => Thrift::Types::LIST, :name => 'ints', :default => [
1,
2,
@@ -94,7 +94,7 @@
MAPS => {:type => Thrift::Types::LIST, :name => 'maps', :element => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I16}, :value => {:type => Thrift::Types::I16}}},
LISTS => {:type => Thrift::Types::LIST, :name => 'lists', :element => {:type => Thrift::Types::LIST, :element => {:type => Thrift::Types::I16}}},
SETS => {:type => Thrift::Types::LIST, :name => 'sets', :element => {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I16}}},
- HELLOS => {:type => Thrift::Types::LIST, :name => 'hellos', :element => {:type => Thrift::Types::STRUCT, :class => Hello}}
+ HELLOS => {:type => Thrift::Types::LIST, :name => 'hellos', :element => {:type => Thrift::Types::STRUCT, :class => SpecNamespace::Hello}}
}
def validate
end