Addressed PR comments.

pull/8850/head
Joshua Haberman 3 years ago
parent d339e1748e
commit b7ab6255d6
  1. 17
      ruby/lib/google/protobuf/descriptor_dsl.rb
  2. 4
      src/google/protobuf/compiler/ruby/ruby_generator.cc

@ -79,7 +79,7 @@ module Google
last_common_dot = nil
min.size.times { |i|
if min[i] != max[i] then break end
if min[i] == ?. then last_common_dot = i end
if min[i] == "." then last_common_dot = i end
}
if last_common_dot
return min.slice(0, last_common_dot)
@ -97,11 +97,11 @@ module Google
value = field.default_value
type_name = field.type_name
if value.empty? or value[0].ord < ?0.ord or value[0].ord > ?9.ord
if value.empty? or value[0].ord < "0".ord or value[0].ord > "9".ord
return
end
if type_name.empty? || type_name[0] != ?.
if type_name.empty? || type_name[0] != "."
return
end
@ -193,14 +193,13 @@ module Google
# above descriptor. We need to infer that "foo" is the package name, and not
# a message itself. */
def get_parent_name(msg_or_enum)
def split_parent_name(msg_or_enum)
name = msg_or_enum.name
idx = name.rindex(?.)
if idx
msg_or_enum.name = name[idx+1..-1]
return name[0...idx]
return name[0...idx], name[idx+1..-1]
else
return nil
return nil, name
end
end
@ -229,7 +228,7 @@ module Google
# Note: We don't iterate over msgs_by_name.values because we want to
# preserve order as listed in the DSL.
@file_proto.message_type.each { |msg|
parent_name = get_parent_name(msg)
parent_name, msg.name = split_parent_name(msg)
if parent_name == package
final_msgs << msg
else
@ -238,7 +237,7 @@ module Google
}
@file_proto.enum_type.each { |enum|
parent_name = get_parent_name(enum)
parent_name, enum.name = split_parent_name(enum)
if parent_name == package
final_enums << enum
else

@ -527,7 +527,7 @@ bool MaybeEmitDependency(const FileDescriptor* import,
}
}
bool GenerateDSLDescriptor(const FileDescriptor* file, io::Printer* printer,
bool GenerateDslDescriptor(const FileDescriptor* file, io::Printer* printer,
std::string* error) {
printer->Print(
"require 'google/protobuf'\n\n");
@ -588,7 +588,7 @@ bool GenerateFile(const FileDescriptor* file, io::Printer* printer,
if (use_raw_descriptor) {
GenerateBinaryDescriptor(file, printer, error);
} else {
GenerateDSLDescriptor(file, printer, error);
GenerateDslDescriptor(file, printer, error);
}
int levels = GeneratePackageModules(file, printer);

Loading…
Cancel
Save