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