| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 : ImmutableMessageFieldLiteGenerator( | 52 : ImmutableMessageFieldLiteGenerator( |
| 53 descriptor, messageBitIndex, builderBitIndex, context) { | 53 descriptor, messageBitIndex, builderBitIndex, context) { |
| 54 } | 54 } |
| 55 | 55 |
| 56 ImmutableLazyMessageFieldLiteGenerator:: | 56 ImmutableLazyMessageFieldLiteGenerator:: |
| 57 ~ImmutableLazyMessageFieldLiteGenerator() {} | 57 ~ImmutableLazyMessageFieldLiteGenerator() {} |
| 58 | 58 |
| 59 void ImmutableLazyMessageFieldLiteGenerator:: | 59 void ImmutableLazyMessageFieldLiteGenerator:: |
| 60 GenerateMembers(io::Printer* printer) const { | 60 GenerateMembers(io::Printer* printer) const { |
| 61 printer->Print(variables_, | 61 printer->Print(variables_, |
| 62 "private com.google.protobuf.LazyFieldLite $name$_ =\n" | 62 "private com.google.protobuf.LazyFieldLite $name$_;"); |
| 63 " new com.google.protobuf.LazyFieldLite();\n"); | |
| 64 | 63 |
| 65 PrintExtraFieldInfo(variables_, printer); | 64 PrintExtraFieldInfo(variables_, printer); |
| 66 WriteFieldDocComment(printer, descriptor_); | 65 WriteFieldDocComment(printer, descriptor_); |
| 67 printer->Print(variables_, | 66 if (SupportFieldPresence(descriptor_->file())) { |
| 68 "$deprecation$public boolean has$capitalized_name$() {\n" | 67 printer->Print(variables_, |
| 69 " return $get_has_field_bit_message$;\n" | 68 "$deprecation$public boolean has$capitalized_name$() {\n" |
| 70 "}\n"); | 69 " return $get_has_field_bit_message$;\n" |
| 70 "}\n"); |
| 71 } else { |
| 72 printer->Print(variables_, |
| 73 "$deprecation$public boolean has$capitalized_name$() {\n" |
| 74 " return $name$_ != null;\n" |
| 75 "}\n"); |
| 76 } |
| 71 | 77 |
| 72 WriteFieldDocComment(printer, descriptor_); | 78 WriteFieldDocComment(printer, descriptor_); |
| 73 printer->Print(variables_, | 79 printer->Print(variables_, |
| 74 "$deprecation$public $type$ get$capitalized_name$() {\n" | 80 "$deprecation$public $type$ get$capitalized_name$() {\n" |
| 81 " if ($name$_ == null) {\n" |
| 82 " return $type$.getDefaultInstance();\n" |
| 83 " }\n" |
| 75 " return ($type$) $name$_.getValue($type$.getDefaultInstance());\n" | 84 " return ($type$) $name$_.getValue($type$.getDefaultInstance());\n" |
| 76 "}\n"); | 85 "}\n"); |
| 77 | 86 |
| 78 // Field.Builder setField(Field value) | 87 // Field.Builder setField(Field value) |
| 79 WriteFieldDocComment(printer, descriptor_); | 88 WriteFieldDocComment(printer, descriptor_); |
| 80 printer->Print(variables_, | 89 printer->Print(variables_, |
| 81 "private void set$capitalized_name$($type$ value) {\n" | 90 "private void set$capitalized_name$($type$ value) {\n" |
| 82 " if (value == null) {\n" | 91 " if (value == null) {\n" |
| 83 " throw new NullPointerException();\n" | 92 " throw new NullPointerException();\n" |
| 84 " }\n" | 93 " }\n" |
| 94 " if ($name$_ == null) {\n" |
| 95 " $name$_ = new com.google.protobuf.LazyFieldLite();\n" |
| 96 " }\n" |
| 85 " $name$_.setValue(value);\n" | 97 " $name$_.setValue(value);\n" |
| 86 " $set_has_field_bit_message$;\n" | 98 " $set_has_field_bit_message$\n" |
| 87 "}\n"); | 99 "}\n"); |
| 88 | 100 |
| 89 // Field.Builder setField(Field.Builder builderForValue) | 101 // Field.Builder setField(Field.Builder builderForValue) |
| 90 WriteFieldDocComment(printer, descriptor_); | 102 WriteFieldDocComment(printer, descriptor_); |
| 91 printer->Print(variables_, | 103 printer->Print(variables_, |
| 92 "private void set$capitalized_name$(\n" | 104 "private void set$capitalized_name$(\n" |
| 93 " $type$.Builder builderForValue) {\n" | 105 " $type$.Builder builderForValue) {\n" |
| 106 " if ($name$_ == null) {\n" |
| 107 " $name$_ = new com.google.protobuf.LazyFieldLite();\n" |
| 108 " }\n" |
| 94 " $name$_.setValue(builderForValue.build());\n" | 109 " $name$_.setValue(builderForValue.build());\n" |
| 95 " $set_has_field_bit_message$;\n" | 110 " $set_has_field_bit_message$\n" |
| 96 "}\n"); | 111 "}\n"); |
| 97 | 112 |
| 98 // Field.Builder mergeField(Field value) | 113 // Field.Builder mergeField(Field value) |
| 99 WriteFieldDocComment(printer, descriptor_); | 114 WriteFieldDocComment(printer, descriptor_); |
| 100 printer->Print(variables_, | 115 printer->Print(variables_, |
| 101 "private void merge$capitalized_name$($type$ value) {\n" | 116 "private void merge$capitalized_name$($type$ value) {\n" |
| 102 " if ($get_has_field_bit_message$ &&\n" | 117 " if (has$capitalized_name$() &&\n" |
| 103 " !$name$_.containsDefaultInstance()) {\n" | 118 " !$name$_.containsDefaultInstance()) {\n" |
| 104 " $name$_.setValue(\n" | 119 " $name$_.setValue(\n" |
| 105 " $type$.newBuilder(\n" | 120 " $type$.newBuilder(\n" |
| 106 " get$capitalized_name$()).mergeFrom(value).buildPartial());\n" | 121 " get$capitalized_name$()).mergeFrom(value).buildPartial());\n" |
| 107 " } else {\n" | 122 " } else {\n" |
| 123 " if ($name$_ == null) {\n" |
| 124 " $name$_ = new com.google.protobuf.LazyFieldLite();\n" |
| 125 " }\n" |
| 108 " $name$_.setValue(value);\n" | 126 " $name$_.setValue(value);\n" |
| 127 " $set_has_field_bit_message$\n" |
| 109 " }\n" | 128 " }\n" |
| 110 " $set_has_field_bit_message$;\n" | |
| 111 "}\n"); | 129 "}\n"); |
| 112 | 130 |
| 113 // Field.Builder clearField() | 131 // Field.Builder clearField() |
| 114 WriteFieldDocComment(printer, descriptor_); | 132 WriteFieldDocComment(printer, descriptor_); |
| 115 printer->Print(variables_, | 133 printer->Print(variables_, |
| 116 "private void clear$capitalized_name$() {\n" | 134 "private void clear$capitalized_name$() {\n" |
| 117 " $name$_.clear();\n" | 135 " $name$_ = null;\n" |
| 118 " $clear_has_field_bit_message$;\n" | 136 " $clear_has_field_bit_message$;\n" |
| 119 "}\n"); | 137 "}\n"); |
| 120 } | 138 } |
| 121 | 139 |
| 122 void ImmutableLazyMessageFieldLiteGenerator:: | 140 void ImmutableLazyMessageFieldLiteGenerator:: |
| 123 GenerateBuilderMembers(io::Printer* printer) const { | 141 GenerateBuilderMembers(io::Printer* printer) const { |
| 124 // The comments above the methods below are based on a hypothetical | 142 // The comments above the methods below are based on a hypothetical |
| 125 // field of type "Field" called "Field". | 143 // field of type "Field" called "Field". |
| 126 | 144 |
| 127 // boolean hasField() | 145 // boolean hasField() |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 printer->Print(variables_, | 188 printer->Print(variables_, |
| 171 "$deprecation$public Builder clear$capitalized_name$() {\n" | 189 "$deprecation$public Builder clear$capitalized_name$() {\n" |
| 172 " copyOnWrite();\n" | 190 " copyOnWrite();\n" |
| 173 " instance.clear$capitalized_name$();\n" | 191 " instance.clear$capitalized_name$();\n" |
| 174 " return this;\n" | 192 " return this;\n" |
| 175 "}\n"); | 193 "}\n"); |
| 176 } | 194 } |
| 177 | 195 |
| 178 | 196 |
| 179 void ImmutableLazyMessageFieldLiteGenerator:: | 197 void ImmutableLazyMessageFieldLiteGenerator:: |
| 180 GenerateInitializationCode(io::Printer* printer) const { | 198 GenerateInitializationCode(io::Printer* printer) const {} |
| 181 printer->Print(variables_, "$name$_.clear();\n"); | |
| 182 } | |
| 183 | 199 |
| 184 void ImmutableLazyMessageFieldLiteGenerator:: | 200 void ImmutableLazyMessageFieldLiteGenerator:: |
| 185 GenerateVisitCode(io::Printer* printer) const { | 201 GenerateVisitCode(io::Printer* printer) const { |
| 186 printer->Print(variables_, | 202 printer->Print(variables_, |
| 187 "$name$_ = visitor.visitLazyMessage(\n" | 203 "$name$_ = visitor.visitLazyMessage($name$_, other.$name$_);\n"); |
| 188 " has$capitalized_name$(), $name$_,\n" | |
| 189 " other.has$capitalized_name$(), other.$name$_);\n"); | |
| 190 } | 204 } |
| 191 | 205 |
| 192 void ImmutableLazyMessageFieldLiteGenerator:: | 206 void ImmutableLazyMessageFieldLiteGenerator:: |
| 193 GenerateParsingCode(io::Printer* printer) const { | 207 GenerateParsingCode(io::Printer* printer) const { |
| 194 printer->Print(variables_, | 208 printer->Print(variables_, |
| 209 "if ($name$_ == null) {\n" |
| 210 " $name$_ = new com.google.protobuf.LazyFieldLite();\n" |
| 211 "}\n" |
| 195 "$name$_.mergeFrom(input, extensionRegistry);\n"); | 212 "$name$_.mergeFrom(input, extensionRegistry);\n"); |
| 196 printer->Print(variables_, | 213 printer->Print(variables_, |
| 197 "$set_has_field_bit_message$;\n"); | 214 "$set_has_field_bit_message$\n"); |
| 198 } | 215 } |
| 199 | 216 |
| 200 void ImmutableLazyMessageFieldLiteGenerator:: | 217 void ImmutableLazyMessageFieldLiteGenerator:: |
| 201 GenerateSerializationCode(io::Printer* printer) const { | 218 GenerateSerializationCode(io::Printer* printer) const { |
| 202 // Do not de-serialize lazy fields. | 219 // Do not de-serialize lazy fields. |
| 203 printer->Print(variables_, | 220 printer->Print(variables_, |
| 204 "if ($get_has_field_bit_message$) {\n" | 221 "if (has$capitalized_name$()) {\n" |
| 205 " output.writeBytes($number$, $name$_.toByteString());\n" | 222 " output.writeBytes($number$, $name$_.toByteString());\n" |
| 206 "}\n"); | 223 "}\n"); |
| 207 } | 224 } |
| 208 | 225 |
| 209 void ImmutableLazyMessageFieldLiteGenerator:: | 226 void ImmutableLazyMessageFieldLiteGenerator:: |
| 210 GenerateSerializedSizeCode(io::Printer* printer) const { | 227 GenerateSerializedSizeCode(io::Printer* printer) const { |
| 211 printer->Print(variables_, | 228 printer->Print(variables_, |
| 212 "if ($get_has_field_bit_message$) {\n" | 229 "if (has$capitalized_name$()) {\n" |
| 213 " size += com.google.protobuf.CodedOutputStream\n" | 230 " size += com.google.protobuf.CodedOutputStream\n" |
| 214 " .computeLazyFieldSize($number$, $name$_);\n" | 231 " .computeLazyFieldSize($number$, $name$_);\n" |
| 215 "}\n"); | 232 "}\n"); |
| 216 } | 233 } |
| 217 | 234 |
| 218 // =================================================================== | 235 // =================================================================== |
| 219 | 236 |
| 220 ImmutableLazyMessageOneofFieldLiteGenerator:: | 237 ImmutableLazyMessageOneofFieldLiteGenerator:: |
| 221 ImmutableLazyMessageOneofFieldLiteGenerator(const FieldDescriptor* descriptor, | 238 ImmutableLazyMessageOneofFieldLiteGenerator(const FieldDescriptor* descriptor, |
| 222 int messageBitIndex, | 239 int messageBitIndex, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 PrintExtraFieldInfo(variables_, printer); | 439 PrintExtraFieldInfo(variables_, printer); |
| 423 WriteFieldDocComment(printer, descriptor_); | 440 WriteFieldDocComment(printer, descriptor_); |
| 424 printer->Print(variables_, | 441 printer->Print(variables_, |
| 425 "$deprecation$public java.util.List<$type$>\n" | 442 "$deprecation$public java.util.List<$type$>\n" |
| 426 " get$capitalized_name$List() {\n" | 443 " get$capitalized_name$List() {\n" |
| 427 " java.util.List<$type$> list =\n" | 444 " java.util.List<$type$> list =\n" |
| 428 " new java.util.ArrayList<$type$>($name$_.size());\n" | 445 " new java.util.ArrayList<$type$>($name$_.size());\n" |
| 429 " for (com.google.protobuf.LazyFieldLite lf : $name$_) {\n" | 446 " for (com.google.protobuf.LazyFieldLite lf : $name$_) {\n" |
| 430 " list.add(($type$) lf.getValue($type$.getDefaultInstance()));\n" | 447 " list.add(($type$) lf.getValue($type$.getDefaultInstance()));\n" |
| 431 " }\n" | 448 " }\n" |
| 432 // TODO(dweis): Make this list immutable? | 449 " return java.util.Collections.unmodifiableList(list);\n" |
| 433 " return list;\n" | |
| 434 "}\n"); | 450 "}\n"); |
| 435 WriteFieldDocComment(printer, descriptor_); | 451 WriteFieldDocComment(printer, descriptor_); |
| 436 printer->Print(variables_, | 452 printer->Print(variables_, |
| 437 "$deprecation$public java.util.List<? extends $type$OrBuilder>\n" | 453 "$deprecation$public java.util.List<? extends $type$OrBuilder>\n" |
| 438 " get$capitalized_name$OrBuilderList() {\n" | 454 " get$capitalized_name$OrBuilderList() {\n" |
| 439 " return get$capitalized_name$List();\n" | 455 " return get$capitalized_name$List();\n" |
| 440 "}\n"); | 456 "}\n"); |
| 441 WriteFieldDocComment(printer, descriptor_); | 457 WriteFieldDocComment(printer, descriptor_); |
| 442 printer->Print(variables_, | 458 printer->Print(variables_, |
| 443 "$deprecation$public int get$capitalized_name$Count() {\n" | 459 "$deprecation$public int get$capitalized_name$Count() {\n" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 "for (int i = 0; i < $name$_.size(); i++) {\n" | 713 "for (int i = 0; i < $name$_.size(); i++) {\n" |
| 698 " size += com.google.protobuf.CodedOutputStream\n" | 714 " size += com.google.protobuf.CodedOutputStream\n" |
| 699 " .computeLazyFieldSize($number$, $name$_.get(i));\n" | 715 " .computeLazyFieldSize($number$, $name$_.get(i));\n" |
| 700 "}\n"); | 716 "}\n"); |
| 701 } | 717 } |
| 702 | 718 |
| 703 } // namespace java | 719 } // namespace java |
| 704 } // namespace compiler | 720 } // namespace compiler |
| 705 } // namespace protobuf | 721 } // namespace protobuf |
| 706 } // namespace google | 722 } // namespace google |
| OLD | NEW |