temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 2 | // Copyright 2008 Google Inc. All rights reserved. |
Feng Xiao | e428862 | 2014-10-01 16:26:23 -0700 | [diff] [blame] | 3 | // https://developers.google.com/protocol-buffers/ |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 4 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 8 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 9 | // * Redistributions of source code must retain the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer. |
| 11 | // * Redistributions in binary form must reproduce the above |
| 12 | // copyright notice, this list of conditions and the following disclaimer |
| 13 | // in the documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // * Neither the name of Google Inc. nor the names of its |
| 16 | // contributors may be used to endorse or promote products derived from |
| 17 | // this software without specific prior written permission. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 18 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 30 | |
| 31 | // Author: kenton@google.com (Kenton Varda) |
| 32 | // Based on original Protocol Buffers design by |
| 33 | // Sanjay Ghemawat, Jeff Dean, and others. |
| 34 | |
| 35 | #include <map> |
| 36 | #include <string> |
| 37 | |
Feng Xiao | eee38b0 | 2015-08-22 18:25:48 -0700 | [diff] [blame] | 38 | #include <google/protobuf/stubs/logging.h> |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 39 | #include <google/protobuf/stubs/common.h> |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 40 | #include <google/protobuf/compiler/java/java_context.h> |
| 41 | #include <google/protobuf/compiler/java/java_doc_comment.h> |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 42 | #include <google/protobuf/compiler/java/java_helpers.h> |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 43 | #include <google/protobuf/compiler/java/java_name_resolver.h> |
| 44 | #include <google/protobuf/compiler/java/java_primitive_field.h> |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 45 | #include <google/protobuf/io/printer.h> |
kenton@google.com | 80b1d62 | 2009-07-29 01:13:20 +0000 | [diff] [blame] | 46 | #include <google/protobuf/wire_format.h> |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 47 | #include <google/protobuf/stubs/strutil.h> |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 48 | |
| 49 | namespace google { |
| 50 | namespace protobuf { |
| 51 | namespace compiler { |
| 52 | namespace java { |
| 53 | |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 54 | using internal::WireFormat; |
kenton@google.com | 80b1d62 | 2009-07-29 01:13:20 +0000 | [diff] [blame] | 55 | using internal::WireFormatLite; |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 56 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 57 | namespace { |
| 58 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 59 | void SetPrimitiveVariables(const FieldDescriptor* descriptor, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 60 | int messageBitIndex, |
| 61 | int builderBitIndex, |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 62 | const FieldGeneratorInfo* info, |
| 63 | ClassNameResolver* name_resolver, |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 64 | map<string, string>* variables) { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 65 | SetCommonFieldVariables(descriptor, info, variables); |
| 66 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 67 | (*variables)["type"] = PrimitiveTypeName(GetJavaType(descriptor)); |
| 68 | (*variables)["boxed_type"] = BoxedPrimitiveTypeName(GetJavaType(descriptor)); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 69 | (*variables)["field_type"] = (*variables)["type"]; |
| 70 | (*variables)["field_list_type"] = "java.util.List<" + |
| 71 | (*variables)["boxed_type"] + ">"; |
liujisi@google.com | 295a096 | 2011-07-05 06:16:40 +0000 | [diff] [blame] | 72 | (*variables)["empty_list"] = "java.util.Collections.emptyList()"; |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 73 | (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 74 | (*variables)["default_init"] = IsDefaultValueJavaDefault(descriptor) ? |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 75 | "" : ("= " + ImmutableDefaultValue(descriptor, name_resolver)); |
| 76 | (*variables)["capitalized_type"] = |
| 77 | GetCapitalizedType(descriptor, /* immutable = */ true); |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 78 | if (descriptor->is_packed()) { |
| 79 | (*variables)["tag"] = SimpleItoa(WireFormatLite::MakeTag( |
| 80 | descriptor->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED)); |
| 81 | } else { |
| 82 | (*variables)["tag"] = SimpleItoa(WireFormat::MakeTag(descriptor)); |
| 83 | } |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 84 | (*variables)["tag_size"] = SimpleItoa( |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 85 | WireFormat::TagSize(descriptor->number(), GetType(descriptor))); |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 86 | if (IsReferenceType(GetJavaType(descriptor))) { |
| 87 | (*variables)["null_check"] = |
| 88 | " if (value == null) {\n" |
| 89 | " throw new NullPointerException();\n" |
| 90 | " }\n"; |
| 91 | } else { |
| 92 | (*variables)["null_check"] = ""; |
| 93 | } |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 94 | // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported |
| 95 | // by the proto compiler |
| 96 | (*variables)["deprecation"] = descriptor->options().deprecated() |
| 97 | ? "@java.lang.Deprecated " : ""; |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 98 | int fixed_size = FixedSize(GetType(descriptor)); |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 99 | if (fixed_size != -1) { |
| 100 | (*variables)["fixed_size"] = SimpleItoa(fixed_size); |
| 101 | } |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 102 | (*variables)["on_changed"] = |
| 103 | HasDescriptorMethods(descriptor->containing_type()) ? "onChanged();" : ""; |
| 104 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 105 | if (SupportFieldPresence(descriptor->file())) { |
| 106 | // For singular messages and builders, one bit is used for the hasField bit. |
| 107 | (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); |
| 108 | (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 109 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 110 | // Note that these have a trailing ";". |
| 111 | (*variables)["set_has_field_bit_message"] = |
| 112 | GenerateSetBit(messageBitIndex) + ";"; |
| 113 | (*variables)["set_has_field_bit_builder"] = |
| 114 | GenerateSetBit(builderBitIndex) + ";"; |
| 115 | (*variables)["clear_has_field_bit_builder"] = |
| 116 | GenerateClearBit(builderBitIndex) + ";"; |
| 117 | |
| 118 | (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex); |
| 119 | } else { |
| 120 | (*variables)["set_has_field_bit_message"] = ""; |
| 121 | (*variables)["set_has_field_bit_builder"] = ""; |
| 122 | (*variables)["clear_has_field_bit_builder"] = ""; |
| 123 | |
| 124 | if (descriptor->type() == FieldDescriptor::TYPE_BYTES) { |
| 125 | (*variables)["is_field_present_message"] = |
| 126 | "!" + (*variables)["name"] + "_.isEmpty()"; |
| 127 | } else { |
| 128 | (*variables)["is_field_present_message"] = |
| 129 | (*variables)["name"] + "_ != " + (*variables)["default"]; |
| 130 | } |
| 131 | } |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 132 | |
| 133 | // For repated builders, one bit is used for whether the array is immutable. |
| 134 | (*variables)["get_mutable_bit_builder"] = GenerateGetBit(builderBitIndex); |
| 135 | (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex); |
| 136 | (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex); |
| 137 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 138 | // For repeated fields, one bit is used for whether the array is immutable |
| 139 | // in the parsing constructor. |
| 140 | (*variables)["get_mutable_bit_parser"] = |
| 141 | GenerateGetBitMutableLocal(builderBitIndex); |
| 142 | (*variables)["set_mutable_bit_parser"] = |
| 143 | GenerateSetBitMutableLocal(builderBitIndex); |
| 144 | |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 145 | (*variables)["get_has_field_bit_from_local"] = |
| 146 | GenerateGetBitFromLocal(builderBitIndex); |
| 147 | (*variables)["set_has_field_bit_to_local"] = |
| 148 | GenerateSetBitToLocal(messageBitIndex); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 149 | } |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 150 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 151 | } // namespace |
| 152 | |
| 153 | // =================================================================== |
| 154 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 155 | ImmutablePrimitiveFieldGenerator:: |
| 156 | ImmutablePrimitiveFieldGenerator(const FieldDescriptor* descriptor, |
| 157 | int messageBitIndex, |
| 158 | int builderBitIndex, |
| 159 | Context* context) |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 160 | : descriptor_(descriptor), messageBitIndex_(messageBitIndex), |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 161 | builderBitIndex_(builderBitIndex), context_(context), |
| 162 | name_resolver_(context->GetNameResolver()) { |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 163 | SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 164 | context->GetFieldGeneratorInfo(descriptor), |
| 165 | name_resolver_, &variables_); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 166 | } |
| 167 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 168 | ImmutablePrimitiveFieldGenerator::~ImmutablePrimitiveFieldGenerator() {} |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 169 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 170 | int ImmutablePrimitiveFieldGenerator::GetNumBitsForMessage() const { |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 171 | return 1; |
| 172 | } |
| 173 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 174 | int ImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const { |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 175 | return 1; |
| 176 | } |
| 177 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 178 | void ImmutablePrimitiveFieldGenerator:: |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 179 | GenerateInterfaceMembers(io::Printer* printer) const { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 180 | if (SupportFieldPresence(descriptor_->file())) { |
| 181 | WriteFieldDocComment(printer, descriptor_); |
| 182 | printer->Print(variables_, |
| 183 | "$deprecation$boolean has$capitalized_name$();\n"); |
| 184 | } |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 185 | WriteFieldDocComment(printer, descriptor_); |
| 186 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 187 | "$deprecation$$type$ get$capitalized_name$();\n"); |
| 188 | } |
| 189 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 190 | void ImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 191 | GenerateMembers(io::Printer* printer) const { |
| 192 | printer->Print(variables_, |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 193 | "private $field_type$ $name$_;\n"); |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 194 | PrintExtraFieldInfo(variables_, printer); |
| 195 | if (SupportFieldPresence(descriptor_->file())) { |
| 196 | WriteFieldDocComment(printer, descriptor_); |
| 197 | printer->Print(variables_, |
| 198 | "$deprecation$public boolean has$capitalized_name$() {\n" |
| 199 | " return $get_has_field_bit_message$;\n" |
| 200 | "}\n"); |
| 201 | } |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 202 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 203 | WriteFieldDocComment(printer, descriptor_); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 204 | printer->Print(variables_, |
| 205 | "$deprecation$public $type$ get$capitalized_name$() {\n" |
| 206 | " return $name$_;\n" |
| 207 | "}\n"); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 208 | } |
| 209 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 210 | void ImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 211 | GenerateBuilderMembers(io::Printer* printer) const { |
| 212 | printer->Print(variables_, |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 213 | "private $field_type$ $name$_ $default_init$;\n"); |
| 214 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 215 | if (SupportFieldPresence(descriptor_->file())) { |
| 216 | WriteFieldDocComment(printer, descriptor_); |
| 217 | printer->Print(variables_, |
| 218 | "$deprecation$public boolean has$capitalized_name$() {\n" |
| 219 | " return $get_has_field_bit_builder$;\n" |
| 220 | "}\n"); |
| 221 | } |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 222 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 223 | WriteFieldDocComment(printer, descriptor_); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 224 | printer->Print(variables_, |
| 225 | "$deprecation$public $type$ get$capitalized_name$() {\n" |
| 226 | " return $name$_;\n" |
| 227 | "}\n"); |
| 228 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 229 | WriteFieldDocComment(printer, descriptor_); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 230 | printer->Print(variables_, |
| 231 | "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 232 | "$null_check$" |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 233 | " $set_has_field_bit_builder$\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 234 | " $name$_ = value;\n" |
| 235 | " $on_changed$\n" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 236 | " return this;\n" |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 237 | "}\n"); |
| 238 | |
| 239 | WriteFieldDocComment(printer, descriptor_); |
| 240 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 241 | "$deprecation$public Builder clear$capitalized_name$() {\n" |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 242 | " $clear_has_field_bit_builder$\n"); |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 243 | JavaType type = GetJavaType(descriptor_); |
| 244 | if (type == JAVATYPE_STRING || type == JAVATYPE_BYTES) { |
kenton@google.com | 80b1d62 | 2009-07-29 01:13:20 +0000 | [diff] [blame] | 245 | // The default value is not a simple literal so we want to avoid executing |
| 246 | // it multiple times. Instead, get the default out of the default instance. |
| 247 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 248 | " $name$_ = getDefaultInstance().get$capitalized_name$();\n"); |
kenton@google.com | 80b1d62 | 2009-07-29 01:13:20 +0000 | [diff] [blame] | 249 | } else { |
| 250 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 251 | " $name$_ = $default$;\n"); |
kenton@google.com | 80b1d62 | 2009-07-29 01:13:20 +0000 | [diff] [blame] | 252 | } |
| 253 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 254 | " $on_changed$\n" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 255 | " return this;\n" |
| 256 | "}\n"); |
| 257 | } |
| 258 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 259 | void ImmutablePrimitiveFieldGenerator:: |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 260 | GenerateFieldBuilderInitializationCode(io::Printer* printer) const { |
| 261 | // noop for primitives |
| 262 | } |
| 263 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 264 | void ImmutablePrimitiveFieldGenerator:: |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 265 | GenerateInitializationCode(io::Printer* printer) const { |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 266 | printer->Print(variables_, "$name$_ = $default$;\n"); |
| 267 | } |
| 268 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 269 | void ImmutablePrimitiveFieldGenerator:: |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 270 | GenerateBuilderClearCode(io::Printer* printer) const { |
| 271 | printer->Print(variables_, |
| 272 | "$name$_ = $default$;\n" |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 273 | "$clear_has_field_bit_builder$\n"); |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 274 | } |
| 275 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 276 | void ImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 277 | GenerateMergingCode(io::Printer* printer) const { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 278 | if (SupportFieldPresence(descriptor_->file())) { |
| 279 | printer->Print(variables_, |
| 280 | "if (other.has$capitalized_name$()) {\n" |
| 281 | " set$capitalized_name$(other.get$capitalized_name$());\n" |
| 282 | "}\n"); |
| 283 | } else { |
| 284 | printer->Print(variables_, |
| 285 | "if (other.get$capitalized_name$() != $default$) {\n" |
| 286 | " set$capitalized_name$(other.get$capitalized_name$());\n" |
| 287 | "}\n"); |
| 288 | } |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 289 | } |
| 290 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 291 | void ImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 292 | GenerateBuildingCode(io::Printer* printer) const { |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 293 | if (SupportFieldPresence(descriptor_->file())) { |
| 294 | printer->Print(variables_, |
| 295 | "if ($get_has_field_bit_from_local$) {\n" |
| 296 | " $set_has_field_bit_to_local$;\n" |
| 297 | "}\n"); |
| 298 | } |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 299 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 300 | "result.$name$_ = $name$_;\n"); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 301 | } |
| 302 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 303 | void ImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 304 | GenerateParsingCode(io::Printer* printer) const { |
| 305 | printer->Print(variables_, |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 306 | "$set_has_field_bit_message$\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 307 | "$name$_ = input.read$capitalized_type$();\n"); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 308 | } |
| 309 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 310 | void ImmutablePrimitiveFieldGenerator:: |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 311 | GenerateParsingDoneCode(io::Printer* printer) const { |
| 312 | // noop for primitives. |
| 313 | } |
| 314 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 315 | void ImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 316 | GenerateSerializationCode(io::Printer* printer) const { |
kenton@google.com | a4a9ef8 | 2010-09-17 23:20:04 +0000 | [diff] [blame] | 317 | printer->Print(variables_, |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 318 | "if ($is_field_present_message$) {\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 319 | " output.write$capitalized_type$($number$, $name$_);\n" |
kenton@google.com | a4a9ef8 | 2010-09-17 23:20:04 +0000 | [diff] [blame] | 320 | "}\n"); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 321 | } |
| 322 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 323 | void ImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 324 | GenerateSerializedSizeCode(io::Printer* printer) const { |
kenton@google.com | a4a9ef8 | 2010-09-17 23:20:04 +0000 | [diff] [blame] | 325 | printer->Print(variables_, |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 326 | "if ($is_field_present_message$) {\n" |
kenton@google.com | a4a9ef8 | 2010-09-17 23:20:04 +0000 | [diff] [blame] | 327 | " size += com.google.protobuf.CodedOutputStream\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 328 | " .compute$capitalized_type$Size($number$, $name$_);\n" |
kenton@google.com | a4a9ef8 | 2010-09-17 23:20:04 +0000 | [diff] [blame] | 329 | "}\n"); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 330 | } |
| 331 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 332 | void ImmutablePrimitiveFieldGenerator:: |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 333 | GenerateEqualsCode(io::Printer* printer) const { |
| 334 | switch (GetJavaType(descriptor_)) { |
| 335 | case JAVATYPE_INT: |
| 336 | case JAVATYPE_LONG: |
| 337 | case JAVATYPE_BOOLEAN: |
| 338 | printer->Print(variables_, |
| 339 | "result = result && (get$capitalized_name$()\n" |
| 340 | " == other.get$capitalized_name$());\n"); |
| 341 | break; |
| 342 | |
| 343 | case JAVATYPE_FLOAT: |
| 344 | printer->Print(variables_, |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 345 | "result = result && (\n" |
| 346 | " java.lang.Float.floatToIntBits(get$capitalized_name$())\n" |
| 347 | " == java.lang.Float.floatToIntBits(\n" |
| 348 | " other.get$capitalized_name$()));\n"); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 349 | break; |
| 350 | |
| 351 | case JAVATYPE_DOUBLE: |
| 352 | printer->Print(variables_, |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 353 | "result = result && (\n" |
| 354 | " java.lang.Double.doubleToLongBits(get$capitalized_name$())\n" |
| 355 | " == java.lang.Double.doubleToLongBits(\n" |
| 356 | " other.get$capitalized_name$()));\n"); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 357 | break; |
| 358 | |
| 359 | case JAVATYPE_STRING: |
| 360 | case JAVATYPE_BYTES: |
| 361 | printer->Print(variables_, |
| 362 | "result = result && get$capitalized_name$()\n" |
| 363 | " .equals(other.get$capitalized_name$());\n"); |
| 364 | break; |
| 365 | |
| 366 | case JAVATYPE_ENUM: |
| 367 | case JAVATYPE_MESSAGE: |
| 368 | default: |
| 369 | GOOGLE_LOG(FATAL) << "Can't get here."; |
| 370 | break; |
| 371 | } |
| 372 | } |
| 373 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 374 | void ImmutablePrimitiveFieldGenerator:: |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 375 | GenerateHashCode(io::Printer* printer) const { |
| 376 | printer->Print(variables_, |
| 377 | "hash = (37 * hash) + $constant_name$;\n"); |
| 378 | switch (GetJavaType(descriptor_)) { |
| 379 | case JAVATYPE_INT: |
| 380 | printer->Print(variables_, |
| 381 | "hash = (53 * hash) + get$capitalized_name$();\n"); |
| 382 | break; |
| 383 | |
| 384 | case JAVATYPE_LONG: |
| 385 | printer->Print(variables_, |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 386 | "hash = (53 * hash) + com.google.protobuf.Internal.hashLong(\n" |
| 387 | " get$capitalized_name$());\n"); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 388 | break; |
| 389 | |
| 390 | case JAVATYPE_BOOLEAN: |
| 391 | printer->Print(variables_, |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 392 | "hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean(\n" |
| 393 | " get$capitalized_name$());\n"); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 394 | break; |
| 395 | |
| 396 | case JAVATYPE_FLOAT: |
| 397 | printer->Print(variables_, |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 398 | "hash = (53 * hash) + java.lang.Float.floatToIntBits(\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 399 | " get$capitalized_name$());\n"); |
| 400 | break; |
| 401 | |
| 402 | case JAVATYPE_DOUBLE: |
| 403 | printer->Print(variables_, |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 404 | "hash = (53 * hash) + com.google.protobuf.Internal.hashLong(\n" |
| 405 | " java.lang.Double.doubleToLongBits(get$capitalized_name$()));\n"); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 406 | break; |
| 407 | |
| 408 | case JAVATYPE_STRING: |
| 409 | case JAVATYPE_BYTES: |
| 410 | printer->Print(variables_, |
| 411 | "hash = (53 * hash) + get$capitalized_name$().hashCode();\n"); |
| 412 | break; |
| 413 | |
| 414 | case JAVATYPE_ENUM: |
| 415 | case JAVATYPE_MESSAGE: |
| 416 | default: |
| 417 | GOOGLE_LOG(FATAL) << "Can't get here."; |
| 418 | break; |
| 419 | } |
| 420 | } |
| 421 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 422 | string ImmutablePrimitiveFieldGenerator::GetBoxedType() const { |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 423 | return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); |
| 424 | } |
| 425 | |
| 426 | // =================================================================== |
| 427 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 428 | ImmutablePrimitiveOneofFieldGenerator:: |
| 429 | ImmutablePrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor, |
| 430 | int messageBitIndex, |
| 431 | int builderBitIndex, |
| 432 | Context* context) |
| 433 | : ImmutablePrimitiveFieldGenerator( |
| 434 | descriptor, messageBitIndex, builderBitIndex, context) { |
| 435 | const OneofGeneratorInfo* info = |
| 436 | context->GetOneofGeneratorInfo(descriptor->containing_oneof()); |
| 437 | SetCommonOneofVariables(descriptor, info, &variables_); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 438 | } |
| 439 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 440 | ImmutablePrimitiveOneofFieldGenerator:: |
| 441 | ~ImmutablePrimitiveOneofFieldGenerator() {} |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 442 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 443 | void ImmutablePrimitiveOneofFieldGenerator:: |
| 444 | GenerateMembers(io::Printer* printer) const { |
| 445 | PrintExtraFieldInfo(variables_, printer); |
| 446 | if (SupportFieldPresence(descriptor_->file())) { |
| 447 | WriteFieldDocComment(printer, descriptor_); |
| 448 | printer->Print(variables_, |
| 449 | "$deprecation$public boolean has$capitalized_name$() {\n" |
| 450 | " return $has_oneof_case_message$;\n" |
| 451 | "}\n"); |
| 452 | } |
| 453 | |
| 454 | WriteFieldDocComment(printer, descriptor_); |
| 455 | printer->Print(variables_, |
| 456 | "$deprecation$public $type$ get$capitalized_name$() {\n" |
| 457 | " if ($has_oneof_case_message$) {\n" |
| 458 | " return ($boxed_type$) $oneof_name$_;\n" |
| 459 | " }\n" |
| 460 | " return $default$;\n" |
| 461 | "}\n"); |
| 462 | } |
| 463 | |
| 464 | |
| 465 | void ImmutablePrimitiveOneofFieldGenerator:: |
| 466 | GenerateBuilderMembers(io::Printer* printer) const { |
| 467 | if (SupportFieldPresence(descriptor_->file())) { |
| 468 | WriteFieldDocComment(printer, descriptor_); |
| 469 | printer->Print(variables_, |
| 470 | "$deprecation$public boolean has$capitalized_name$() {\n" |
| 471 | " return $has_oneof_case_message$;\n" |
| 472 | "}\n"); |
| 473 | } |
| 474 | |
| 475 | WriteFieldDocComment(printer, descriptor_); |
| 476 | printer->Print(variables_, |
| 477 | "$deprecation$public $type$ get$capitalized_name$() {\n" |
| 478 | " if ($has_oneof_case_message$) {\n" |
| 479 | " return ($boxed_type$) $oneof_name$_;\n" |
| 480 | " }\n" |
| 481 | " return $default$;\n" |
| 482 | "}\n"); |
| 483 | |
| 484 | WriteFieldDocComment(printer, descriptor_); |
| 485 | printer->Print(variables_, |
| 486 | "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" |
| 487 | "$null_check$" |
| 488 | " $set_oneof_case_message$;\n" |
| 489 | " $oneof_name$_ = value;\n" |
| 490 | " $on_changed$\n" |
| 491 | " return this;\n" |
| 492 | "}\n"); |
| 493 | |
| 494 | WriteFieldDocComment(printer, descriptor_); |
| 495 | printer->Print(variables_, |
| 496 | "$deprecation$public Builder clear$capitalized_name$() {\n" |
| 497 | " if ($has_oneof_case_message$) {\n" |
| 498 | " $clear_oneof_case_message$;\n" |
| 499 | " $oneof_name$_ = null;\n" |
| 500 | " $on_changed$\n" |
| 501 | " }\n" |
| 502 | " return this;\n" |
| 503 | "}\n"); |
| 504 | } |
| 505 | |
| 506 | void ImmutablePrimitiveOneofFieldGenerator:: |
| 507 | GenerateBuildingCode(io::Printer* printer) const { |
| 508 | printer->Print(variables_, |
| 509 | "if ($has_oneof_case_message$) {\n" |
| 510 | " result.$oneof_name$_ = $oneof_name$_;\n" |
| 511 | "}\n"); |
| 512 | } |
| 513 | |
| 514 | void ImmutablePrimitiveOneofFieldGenerator:: |
| 515 | GenerateMergingCode(io::Printer* printer) const { |
| 516 | printer->Print(variables_, |
| 517 | "set$capitalized_name$(other.get$capitalized_name$());\n"); |
| 518 | } |
| 519 | |
| 520 | void ImmutablePrimitiveOneofFieldGenerator:: |
| 521 | GenerateParsingCode(io::Printer* printer) const { |
| 522 | printer->Print(variables_, |
| 523 | "$set_oneof_case_message$;\n" |
| 524 | "$oneof_name$_ = input.read$capitalized_type$();\n"); |
| 525 | } |
| 526 | |
| 527 | void ImmutablePrimitiveOneofFieldGenerator:: |
| 528 | GenerateSerializationCode(io::Printer* printer) const { |
| 529 | printer->Print(variables_, |
| 530 | "if ($has_oneof_case_message$) {\n" |
| 531 | " output.write$capitalized_type$(\n" |
| 532 | " $number$, ($type$)(($boxed_type$) $oneof_name$_));\n" |
| 533 | "}\n"); |
| 534 | } |
| 535 | |
| 536 | void ImmutablePrimitiveOneofFieldGenerator:: |
| 537 | GenerateSerializedSizeCode(io::Printer* printer) const { |
| 538 | printer->Print(variables_, |
| 539 | "if ($has_oneof_case_message$) {\n" |
| 540 | " size += com.google.protobuf.CodedOutputStream\n" |
| 541 | " .compute$capitalized_type$Size(\n" |
| 542 | " $number$, ($type$)(($boxed_type$) $oneof_name$_));\n" |
| 543 | "}\n"); |
| 544 | } |
| 545 | |
| 546 | // =================================================================== |
| 547 | |
| 548 | RepeatedImmutablePrimitiveFieldGenerator:: |
| 549 | RepeatedImmutablePrimitiveFieldGenerator(const FieldDescriptor* descriptor, |
| 550 | int messageBitIndex, |
| 551 | int builderBitIndex, |
| 552 | Context* context) |
| 553 | : descriptor_(descriptor), messageBitIndex_(messageBitIndex), |
| 554 | builderBitIndex_(builderBitIndex), context_(context), |
| 555 | name_resolver_(context->GetNameResolver()) { |
| 556 | SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, |
| 557 | context->GetFieldGeneratorInfo(descriptor), |
| 558 | name_resolver_, &variables_); |
| 559 | } |
| 560 | |
| 561 | RepeatedImmutablePrimitiveFieldGenerator:: |
| 562 | ~RepeatedImmutablePrimitiveFieldGenerator() {} |
| 563 | |
| 564 | int RepeatedImmutablePrimitiveFieldGenerator::GetNumBitsForMessage() const { |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 565 | return 0; |
| 566 | } |
| 567 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 568 | int RepeatedImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const { |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 569 | return 1; |
| 570 | } |
| 571 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 572 | void RepeatedImmutablePrimitiveFieldGenerator:: |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 573 | GenerateInterfaceMembers(io::Printer* printer) const { |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 574 | WriteFieldDocComment(printer, descriptor_); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 575 | printer->Print(variables_, |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 576 | "$deprecation$java.util.List<$boxed_type$> get$capitalized_name$List();\n"); |
| 577 | WriteFieldDocComment(printer, descriptor_); |
| 578 | printer->Print(variables_, |
| 579 | "$deprecation$int get$capitalized_name$Count();\n"); |
| 580 | WriteFieldDocComment(printer, descriptor_); |
| 581 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 582 | "$deprecation$$type$ get$capitalized_name$(int index);\n"); |
| 583 | } |
| 584 | |
| 585 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 586 | void RepeatedImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 587 | GenerateMembers(io::Printer* printer) const { |
| 588 | printer->Print(variables_, |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 589 | "private $field_list_type$ $name$_;\n"); |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 590 | PrintExtraFieldInfo(variables_, printer); |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 591 | WriteFieldDocComment(printer, descriptor_); |
| 592 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 593 | "$deprecation$public java.util.List<$boxed_type$>\n" |
| 594 | " get$capitalized_name$List() {\n" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 595 | " return $name$_;\n" // note: unmodifiable list |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 596 | "}\n"); |
| 597 | WriteFieldDocComment(printer, descriptor_); |
| 598 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 599 | "$deprecation$public int get$capitalized_name$Count() {\n" |
| 600 | " return $name$_.size();\n" |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 601 | "}\n"); |
| 602 | WriteFieldDocComment(printer, descriptor_); |
| 603 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 604 | "$deprecation$public $type$ get$capitalized_name$(int index) {\n" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 605 | " return $name$_.get(index);\n" |
| 606 | "}\n"); |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 607 | |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 608 | if (descriptor_->is_packed() && |
kenton@google.com | 80b1d62 | 2009-07-29 01:13:20 +0000 | [diff] [blame] | 609 | HasGeneratedMethods(descriptor_->containing_type())) { |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 610 | printer->Print(variables_, |
jasonh+personal@google.com | 9951233 | 2009-12-01 18:05:21 +0000 | [diff] [blame] | 611 | "private int $name$MemoizedSerializedSize = -1;\n"); |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 612 | } |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 613 | } |
| 614 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 615 | void RepeatedImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 616 | GenerateBuilderMembers(io::Printer* printer) const { |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 617 | // One field is the list and the bit field keeps track of whether the |
| 618 | // list is immutable. If it's immutable, the invariant is that it must |
| 619 | // either an instance of Collections.emptyList() or it's an ArrayList |
| 620 | // wrapped in a Collections.unmodifiableList() wrapper and nobody else has |
| 621 | // a refererence to the underlying ArrayList. This invariant allows us to |
| 622 | // share instances of lists between protocol buffers avoiding expensive |
| 623 | // memory allocations. Note, immutable is a strong guarantee here -- not |
| 624 | // just that the list cannot be modified via the reference but that the |
| 625 | // list can never be modified. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 626 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 627 | "private $field_list_type$ $name$_ = $empty_list$;\n"); |
| 628 | |
| 629 | printer->Print(variables_, |
| 630 | "private void ensure$capitalized_name$IsMutable() {\n" |
| 631 | " if (!$get_mutable_bit_builder$) {\n" |
| 632 | " $name$_ = new java.util.ArrayList<$boxed_type$>($name$_);\n" |
| 633 | " $set_mutable_bit_builder$;\n" |
| 634 | " }\n" |
| 635 | "}\n"); |
| 636 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 637 | // Note: We return an unmodifiable list because otherwise the caller |
| 638 | // could hold on to the returned list and modify it after the message |
| 639 | // has been built, thus mutating the message which is supposed to be |
| 640 | // immutable. |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 641 | WriteFieldDocComment(printer, descriptor_); |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 642 | printer->Print(variables_, |
| 643 | "$deprecation$public java.util.List<$boxed_type$>\n" |
| 644 | " get$capitalized_name$List() {\n" |
| 645 | " return java.util.Collections.unmodifiableList($name$_);\n" |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 646 | "}\n"); |
| 647 | WriteFieldDocComment(printer, descriptor_); |
| 648 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 649 | "$deprecation$public int get$capitalized_name$Count() {\n" |
| 650 | " return $name$_.size();\n" |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 651 | "}\n"); |
| 652 | WriteFieldDocComment(printer, descriptor_); |
| 653 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 654 | "$deprecation$public $type$ get$capitalized_name$(int index) {\n" |
| 655 | " return $name$_.get(index);\n" |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 656 | "}\n"); |
| 657 | WriteFieldDocComment(printer, descriptor_); |
| 658 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 659 | "$deprecation$public Builder set$capitalized_name$(\n" |
| 660 | " int index, $type$ value) {\n" |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 661 | "$null_check$" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 662 | " ensure$capitalized_name$IsMutable();\n" |
| 663 | " $name$_.set(index, value);\n" |
| 664 | " $on_changed$\n" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 665 | " return this;\n" |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 666 | "}\n"); |
| 667 | WriteFieldDocComment(printer, descriptor_); |
| 668 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 669 | "$deprecation$public Builder add$capitalized_name$($type$ value) {\n" |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 670 | "$null_check$" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 671 | " ensure$capitalized_name$IsMutable();\n" |
| 672 | " $name$_.add(value);\n" |
| 673 | " $on_changed$\n" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 674 | " return this;\n" |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 675 | "}\n"); |
| 676 | WriteFieldDocComment(printer, descriptor_); |
| 677 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 678 | "$deprecation$public Builder addAll$capitalized_name$(\n" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 679 | " java.lang.Iterable<? extends $boxed_type$> values) {\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 680 | " ensure$capitalized_name$IsMutable();\n" |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 681 | " com.google.protobuf.AbstractMessageLite.Builder.addAll(\n" |
| 682 | " values, $name$_);\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 683 | " $on_changed$\n" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 684 | " return this;\n" |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 685 | "}\n"); |
| 686 | WriteFieldDocComment(printer, descriptor_); |
| 687 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 688 | "$deprecation$public Builder clear$capitalized_name$() {\n" |
| 689 | " $name$_ = $empty_list$;\n" |
| 690 | " $clear_mutable_bit_builder$;\n" |
| 691 | " $on_changed$\n" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 692 | " return this;\n" |
| 693 | "}\n"); |
| 694 | } |
| 695 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 696 | void RepeatedImmutablePrimitiveFieldGenerator:: |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 697 | GenerateFieldBuilderInitializationCode(io::Printer* printer) const { |
| 698 | // noop for primitives |
| 699 | } |
| 700 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 701 | void RepeatedImmutablePrimitiveFieldGenerator:: |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 702 | GenerateInitializationCode(io::Printer* printer) const { |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 703 | printer->Print(variables_, "$name$_ = $empty_list$;\n"); |
| 704 | } |
| 705 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 706 | void RepeatedImmutablePrimitiveFieldGenerator:: |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 707 | GenerateBuilderClearCode(io::Printer* printer) const { |
| 708 | printer->Print(variables_, |
| 709 | "$name$_ = $empty_list$;\n" |
| 710 | "$clear_mutable_bit_builder$;\n"); |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 711 | } |
| 712 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 713 | void RepeatedImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 714 | GenerateMergingCode(io::Printer* printer) const { |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 715 | // The code below does two optimizations: |
| 716 | // 1. If the other list is empty, there's nothing to do. This ensures we |
| 717 | // don't allocate a new array if we already have an immutable one. |
| 718 | // 2. If the other list is non-empty and our current list is empty, we can |
| 719 | // reuse the other list which is guaranteed to be immutable. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 720 | printer->Print(variables_, |
| 721 | "if (!other.$name$_.isEmpty()) {\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 722 | " if ($name$_.isEmpty()) {\n" |
| 723 | " $name$_ = other.$name$_;\n" |
| 724 | " $clear_mutable_bit_builder$;\n" |
| 725 | " } else {\n" |
| 726 | " ensure$capitalized_name$IsMutable();\n" |
| 727 | " $name$_.addAll(other.$name$_);\n" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 728 | " }\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 729 | " $on_changed$\n" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 730 | "}\n"); |
| 731 | } |
| 732 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 733 | void RepeatedImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 734 | GenerateBuildingCode(io::Printer* printer) const { |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 735 | // The code below ensures that the result has an immutable list. If our |
| 736 | // list is immutable, we can just reuse it. If not, we make it immutable. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 737 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 738 | "if ($get_mutable_bit_builder$) {\n" |
| 739 | " $name$_ = java.util.Collections.unmodifiableList($name$_);\n" |
| 740 | " $clear_mutable_bit_builder$;\n" |
| 741 | "}\n" |
| 742 | "result.$name$_ = $name$_;\n"); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 743 | } |
| 744 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 745 | void RepeatedImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 746 | GenerateParsingCode(io::Printer* printer) const { |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 747 | printer->Print(variables_, |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 748 | "if (!$get_mutable_bit_parser$) {\n" |
| 749 | " $name$_ = new java.util.ArrayList<$boxed_type$>();\n" |
| 750 | " $set_mutable_bit_parser$;\n" |
| 751 | "}\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 752 | "$name$_.add(input.read$capitalized_type$());\n"); |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 753 | } |
| 754 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 755 | void RepeatedImmutablePrimitiveFieldGenerator:: |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 756 | GenerateParsingCodeFromPacked(io::Printer* printer) const { |
| 757 | printer->Print(variables_, |
| 758 | "int length = input.readRawVarint32();\n" |
| 759 | "int limit = input.pushLimit(length);\n" |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 760 | "if (!$get_mutable_bit_parser$ && input.getBytesUntilLimit() > 0) {\n" |
| 761 | " $name$_ = new java.util.ArrayList<$boxed_type$>();\n" |
| 762 | " $set_mutable_bit_parser$;\n" |
| 763 | "}\n" |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 764 | "while (input.getBytesUntilLimit() > 0) {\n" |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 765 | " $name$_.add(input.read$capitalized_type$());\n" |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 766 | "}\n" |
| 767 | "input.popLimit(limit);\n"); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 768 | } |
| 769 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 770 | void RepeatedImmutablePrimitiveFieldGenerator:: |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 771 | GenerateParsingDoneCode(io::Printer* printer) const { |
| 772 | printer->Print(variables_, |
| 773 | "if ($get_mutable_bit_parser$) {\n" |
| 774 | " $name$_ = java.util.Collections.unmodifiableList($name$_);\n" |
| 775 | "}\n"); |
| 776 | } |
| 777 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 778 | void RepeatedImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 779 | GenerateSerializationCode(io::Printer* printer) const { |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 780 | if (descriptor_->is_packed()) { |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 781 | // We invoke getSerializedSize in writeTo for messages that have packed |
| 782 | // fields in ImmutableMessageGenerator::GenerateMessageSerializationMethods. |
| 783 | // That makes it safe to rely on the memoized size here. |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 784 | printer->Print(variables_, |
| 785 | "if (get$capitalized_name$List().size() > 0) {\n" |
| 786 | " output.writeRawVarint32($tag$);\n" |
| 787 | " output.writeRawVarint32($name$MemoizedSerializedSize);\n" |
| 788 | "}\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 789 | "for (int i = 0; i < $name$_.size(); i++) {\n" |
| 790 | " output.write$capitalized_type$NoTag($name$_.get(i));\n" |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 791 | "}\n"); |
| 792 | } else { |
| 793 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 794 | "for (int i = 0; i < $name$_.size(); i++) {\n" |
| 795 | " output.write$capitalized_type$($number$, $name$_.get(i));\n" |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 796 | "}\n"); |
| 797 | } |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 798 | } |
| 799 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 800 | void RepeatedImmutablePrimitiveFieldGenerator:: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 801 | GenerateSerializedSizeCode(io::Printer* printer) const { |
| 802 | printer->Print(variables_, |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 803 | "{\n" |
| 804 | " int dataSize = 0;\n"); |
| 805 | printer->Indent(); |
| 806 | |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 807 | if (FixedSize(GetType(descriptor_)) == -1) { |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 808 | printer->Print(variables_, |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 809 | "for (int i = 0; i < $name$_.size(); i++) {\n" |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 810 | " dataSize += com.google.protobuf.CodedOutputStream\n" |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 811 | " .compute$capitalized_type$SizeNoTag($name$_.get(i));\n" |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 812 | "}\n"); |
| 813 | } else { |
| 814 | printer->Print(variables_, |
| 815 | "dataSize = $fixed_size$ * get$capitalized_name$List().size();\n"); |
| 816 | } |
| 817 | |
| 818 | printer->Print( |
| 819 | "size += dataSize;\n"); |
| 820 | |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 821 | if (descriptor_->is_packed()) { |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 822 | printer->Print(variables_, |
| 823 | "if (!get$capitalized_name$List().isEmpty()) {\n" |
| 824 | " size += $tag_size$;\n" |
| 825 | " size += com.google.protobuf.CodedOutputStream\n" |
| 826 | " .computeInt32SizeNoTag(dataSize);\n" |
| 827 | "}\n"); |
| 828 | } else { |
| 829 | printer->Print(variables_, |
| 830 | "size += $tag_size$ * get$capitalized_name$List().size();\n"); |
| 831 | } |
| 832 | |
| 833 | // cache the data size for packed fields. |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 834 | if (descriptor_->is_packed()) { |
kenton@google.com | 2d6daa7 | 2009-01-22 01:27:00 +0000 | [diff] [blame] | 835 | printer->Print(variables_, |
| 836 | "$name$MemoizedSerializedSize = dataSize;\n"); |
| 837 | } |
| 838 | |
| 839 | printer->Outdent(); |
| 840 | printer->Print("}\n"); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 841 | } |
| 842 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 843 | void RepeatedImmutablePrimitiveFieldGenerator:: |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 844 | GenerateEqualsCode(io::Printer* printer) const { |
| 845 | printer->Print(variables_, |
| 846 | "result = result && get$capitalized_name$List()\n" |
| 847 | " .equals(other.get$capitalized_name$List());\n"); |
| 848 | } |
| 849 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 850 | void RepeatedImmutablePrimitiveFieldGenerator:: |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame] | 851 | GenerateHashCode(io::Printer* printer) const { |
| 852 | printer->Print(variables_, |
| 853 | "if (get$capitalized_name$Count() > 0) {\n" |
| 854 | " hash = (37 * hash) + $constant_name$;\n" |
| 855 | " hash = (53 * hash) + get$capitalized_name$List().hashCode();\n" |
| 856 | "}\n"); |
| 857 | } |
| 858 | |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 859 | string RepeatedImmutablePrimitiveFieldGenerator::GetBoxedType() const { |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 860 | return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); |
| 861 | } |
| 862 | |
| 863 | } // namespace java |
| 864 | } // namespace compiler |
| 865 | } // namespace protobuf |
| 866 | } // namespace google |