aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/javanano/javanano_field.cc
diff options
context:
space:
mode:
authorGravatar Andrew Flynn <flynn@google.com>2013-12-04 13:10:07 -0800
committerGravatar Andrew Flynn <flynn@google.com>2013-12-09 11:40:03 -0800
commitc997c136bbd5a4f7131d21a3f8c45e563fa5cca5 (patch)
tree350188aebfbd906e16b993f3e33e38c3b36681a0 /src/google/protobuf/compiler/javanano/javanano_field.cc
parent2d2557ea706f1da104a8d8fc592177d21852d7ce (diff)
Nano: don't generate accessor methods for nested methods
For nested message objects, don't generate accessor methods because they have a default value that is not a valid value (null), so there is no reason to have get/set/has/clear methods for them. Clients and protos (while serializing) can check against the invalid value to see if it's been set. Change-Id: Ic63400889581271b8cbcd9c45c84519d4921fd4b
Diffstat (limited to 'src/google/protobuf/compiler/javanano/javanano_field.cc')
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_field.cc12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_field.cc b/src/google/protobuf/compiler/javanano/javanano_field.cc
index 62e133e7..25816699 100644
--- a/src/google/protobuf/compiler/javanano/javanano_field.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_field.cc
@@ -78,8 +78,9 @@ FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor, const Params
FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field,
const Params &params, int* next_has_bit_index) {
+ JavaType java_type = GetJavaType(field);
if (field->is_repeated()) {
- switch (GetJavaType(field)) {
+ switch (java_type) {
case JAVATYPE_MESSAGE:
return new RepeatedMessageFieldGenerator(field, params);
case JAVATYPE_ENUM:
@@ -87,14 +88,13 @@ FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field,
default:
return new RepeatedPrimitiveFieldGenerator(field, params);
}
- } else if (params.optional_field_accessors() && field->is_optional()) {
+ } else if (params.optional_field_accessors() && field->is_optional()
+ && java_type != JAVATYPE_MESSAGE) {
// We need a has-bit for each primitive/enum field because their default
// values could be same as explicitly set values. But we don't need it
// for a message field because they have no defaults and Nano uses 'null'
// for unset messages, which cannot be set explicitly.
- switch (GetJavaType(field)) {
- case JAVATYPE_MESSAGE:
- return new AccessorMessageFieldGenerator(field, params);
+ switch (java_type) {
case JAVATYPE_ENUM:
return new AccessorEnumFieldGenerator(
field, params, (*next_has_bit_index)++);
@@ -103,7 +103,7 @@ FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field,
field, params, (*next_has_bit_index)++);
}
} else {
- switch (GetJavaType(field)) {
+ switch (java_type) {
case JAVATYPE_MESSAGE:
return new MessageFieldGenerator(field, params);
case JAVATYPE_ENUM: