| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include <google/protobuf/compiler/java/java_name_resolver.h> | 35 #include <google/protobuf/compiler/java/java_name_resolver.h> |
| 36 #include <google/protobuf/descriptor.h> | 36 #include <google/protobuf/descriptor.h> |
| 37 #include <google/protobuf/stubs/strutil.h> | 37 #include <google/protobuf/stubs/strutil.h> |
| 38 #include <google/protobuf/stubs/map_util.h> | 38 #include <google/protobuf/stubs/map_util.h> |
| 39 | 39 |
| 40 namespace google { | 40 namespace google { |
| 41 namespace protobuf { | 41 namespace protobuf { |
| 42 namespace compiler { | 42 namespace compiler { |
| 43 namespace java { | 43 namespace java { |
| 44 | 44 |
| 45 Context::Context(const FileDescriptor* file) | 45 Context::Context(const FileDescriptor* file, const Options& options) |
| 46 : name_resolver_(new ClassNameResolver), enforce_lite_(false) { | 46 : name_resolver_(new ClassNameResolver), options_(options) { |
| 47 InitializeFieldGeneratorInfo(file); | 47 InitializeFieldGeneratorInfo(file); |
| 48 } | 48 } |
| 49 | 49 |
| 50 Context::~Context() { | 50 Context::~Context() { |
| 51 } | 51 } |
| 52 | 52 |
| 53 ClassNameResolver* Context::GetNameResolver() { | 53 ClassNameResolver* Context::GetNameResolver() { |
| 54 return name_resolver_.get(); | 54 return name_resolver_.get(); |
| 55 } | 55 } |
| 56 | 56 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 for (int i = 0; i < file->message_type_count(); ++i) { | 101 for (int i = 0; i < file->message_type_count(); ++i) { |
| 102 InitializeFieldGeneratorInfoForMessage(file->message_type(i)); | 102 InitializeFieldGeneratorInfoForMessage(file->message_type(i)); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 void Context::InitializeFieldGeneratorInfoForMessage( | 106 void Context::InitializeFieldGeneratorInfoForMessage( |
| 107 const Descriptor* message) { | 107 const Descriptor* message) { |
| 108 for (int i = 0; i < message->nested_type_count(); ++i) { | 108 for (int i = 0; i < message->nested_type_count(); ++i) { |
| 109 InitializeFieldGeneratorInfoForMessage(message->nested_type(i)); | 109 InitializeFieldGeneratorInfoForMessage(message->nested_type(i)); |
| 110 } | 110 } |
| 111 vector<const FieldDescriptor*> fields; | 111 std::vector<const FieldDescriptor*> fields; |
| 112 for (int i = 0; i < message->field_count(); ++i) { | 112 for (int i = 0; i < message->field_count(); ++i) { |
| 113 fields.push_back(message->field(i)); | 113 fields.push_back(message->field(i)); |
| 114 } | 114 } |
| 115 InitializeFieldGeneratorInfoForFields(fields); | 115 InitializeFieldGeneratorInfoForFields(fields); |
| 116 | 116 |
| 117 for (int i = 0; i < message->oneof_decl_count(); ++i) { | 117 for (int i = 0; i < message->oneof_decl_count(); ++i) { |
| 118 const OneofDescriptor* oneof = message->oneof_decl(i); | 118 const OneofDescriptor* oneof = message->oneof_decl(i); |
| 119 OneofGeneratorInfo info; | 119 OneofGeneratorInfo info; |
| 120 info.name = UnderscoresToCamelCase(oneof->name(), false); | 120 info.name = UnderscoresToCamelCase(oneof->name(), false); |
| 121 info.capitalized_name = UnderscoresToCamelCase(oneof->name(), true); | 121 info.capitalized_name = UnderscoresToCamelCase(oneof->name(), true); |
| 122 oneof_generator_info_map_[oneof] = info; | 122 oneof_generator_info_map_[oneof] = info; |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 void Context::InitializeFieldGeneratorInfoForFields( | 126 void Context::InitializeFieldGeneratorInfoForFields( |
| 127 const vector<const FieldDescriptor*>& fields) { | 127 const std::vector<const FieldDescriptor*>& fields) { |
| 128 // Find out all fields that conflict with some other field in the same | 128 // Find out all fields that conflict with some other field in the same |
| 129 // message. | 129 // message. |
| 130 vector<bool> is_conflict(fields.size()); | 130 std::vector<bool> is_conflict(fields.size()); |
| 131 vector<string> conflict_reason(fields.size()); | 131 std::vector<string> conflict_reason(fields.size()); |
| 132 for (int i = 0; i < fields.size(); ++i) { | 132 for (int i = 0; i < fields.size(); ++i) { |
| 133 const FieldDescriptor* field = fields[i]; | 133 const FieldDescriptor* field = fields[i]; |
| 134 const string& name = UnderscoresToCapitalizedCamelCase(field); | 134 const string& name = UnderscoresToCapitalizedCamelCase(field); |
| 135 for (int j = i + 1; j < fields.size(); ++j) { | 135 for (int j = i + 1; j < fields.size(); ++j) { |
| 136 const FieldDescriptor* other = fields[j]; | 136 const FieldDescriptor* other = fields[j]; |
| 137 const string& other_name = UnderscoresToCapitalizedCamelCase(other); | 137 const string& other_name = UnderscoresToCapitalizedCamelCase(other); |
| 138 if (name == other_name) { | 138 if (name == other_name) { |
| 139 is_conflict[i] = is_conflict[j] = true; | 139 is_conflict[i] = is_conflict[j] = true; |
| 140 conflict_reason[i] = conflict_reason[j] = | 140 conflict_reason[i] = conflict_reason[j] = |
| 141 "capitalized name of field \"" + field->name() + | 141 "capitalized name of field \"" + field->name() + |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 if (result == NULL) { | 185 if (result == NULL) { |
| 186 GOOGLE_LOG(FATAL) << "Can not find OneofGeneratorInfo for oneof: " | 186 GOOGLE_LOG(FATAL) << "Can not find OneofGeneratorInfo for oneof: " |
| 187 << oneof->name(); | 187 << oneof->name(); |
| 188 } | 188 } |
| 189 return result; | 189 return result; |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Does this message class have generated parsing, serialization, and other | 192 // Does this message class have generated parsing, serialization, and other |
| 193 // standard methods for which reflection-based fallback implementations exist? | 193 // standard methods for which reflection-based fallback implementations exist? |
| 194 bool Context::HasGeneratedMethods(const Descriptor* descriptor) const { | 194 bool Context::HasGeneratedMethods(const Descriptor* descriptor) const { |
| 195 return enforce_lite_ || descriptor->file()->options().optimize_for() != | 195 return options_.enforce_lite || |
| 196 FileOptions::CODE_SIZE; | 196 descriptor->file()->options().optimize_for() != FileOptions::CODE_SIZE; |
| 197 } | 197 } |
| 198 | 198 |
| 199 } // namespace java | 199 } // namespace java |
| 200 } // namespace compiler | 200 } // namespace compiler |
| 201 } // namespace protobuf | 201 } // namespace protobuf |
| 202 } // namespace google | 202 } // namespace google |
| OLD | NEW |