Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field.cc

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 using internal::WireFormat; 54 using internal::WireFormat;
55 using internal::WireFormatLite; 55 using internal::WireFormatLite;
56 56
57 namespace { 57 namespace {
58 58
59 void SetPrimitiveVariables(const FieldDescriptor* descriptor, 59 void SetPrimitiveVariables(const FieldDescriptor* descriptor,
60 int messageBitIndex, 60 int messageBitIndex,
61 int builderBitIndex, 61 int builderBitIndex,
62 const FieldGeneratorInfo* info, 62 const FieldGeneratorInfo* info,
63 ClassNameResolver* name_resolver, 63 ClassNameResolver* name_resolver,
64 std::map<string, string>* variables) { 64 map<string, string>* variables) {
65 SetCommonFieldVariables(descriptor, info, variables); 65 SetCommonFieldVariables(descriptor, info, variables);
66 66
67 (*variables)["type"] = PrimitiveTypeName(GetJavaType(descriptor)); 67 (*variables)["type"] = PrimitiveTypeName(GetJavaType(descriptor));
68 (*variables)["boxed_type"] = BoxedPrimitiveTypeName(GetJavaType(descriptor)); 68 (*variables)["boxed_type"] = BoxedPrimitiveTypeName(GetJavaType(descriptor));
69 (*variables)["field_type"] = (*variables)["type"]; 69 (*variables)["field_type"] = (*variables)["type"];
70 (*variables)["field_list_type"] = "java.util.List<" + 70 (*variables)["field_list_type"] = "java.util.List<" +
71 (*variables)["boxed_type"] + ">"; 71 (*variables)["boxed_type"] + ">";
72 (*variables)["empty_list"] = "java.util.Collections.emptyList()"; 72 (*variables)["empty_list"] = "java.util.Collections.emptyList()";
73 (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); 73 (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
74 (*variables)["default_init"] = IsDefaultValueJavaDefault(descriptor) ? 74 (*variables)["default_init"] = IsDefaultValueJavaDefault(descriptor) ?
75 "" : ("= " + ImmutableDefaultValue(descriptor, name_resolver)); 75 "" : ("= " + ImmutableDefaultValue(descriptor, name_resolver));
76 (*variables)["capitalized_type"] = 76 (*variables)["capitalized_type"] =
77 GetCapitalizedType(descriptor, /* immutable = */ true); 77 GetCapitalizedType(descriptor, /* immutable = */ true);
78 (*variables)["tag"] = 78 (*variables)["tag"] = SimpleItoa(WireFormat::MakeTag(descriptor));
79 SimpleItoa(static_cast<int32>(WireFormat::MakeTag(descriptor)));
80 (*variables)["tag_size"] = SimpleItoa( 79 (*variables)["tag_size"] = SimpleItoa(
81 WireFormat::TagSize(descriptor->number(), GetType(descriptor))); 80 WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
82 if (IsReferenceType(GetJavaType(descriptor))) { 81 if (IsReferenceType(GetJavaType(descriptor))) {
83 (*variables)["null_check"] = 82 (*variables)["null_check"] =
84 " if (value == null) {\n" 83 " if (value == null) {\n"
85 " throw new NullPointerException();\n" 84 " throw new NullPointerException();\n"
86 " }\n"; 85 " }\n";
87 } else { 86 } else {
88 (*variables)["null_check"] = ""; 87 (*variables)["null_check"] = "";
89 } 88 }
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 } 770 }
772 771
773 void RepeatedImmutablePrimitiveFieldGenerator:: 772 void RepeatedImmutablePrimitiveFieldGenerator::
774 GenerateSerializationCode(io::Printer* printer) const { 773 GenerateSerializationCode(io::Printer* printer) const {
775 if (descriptor_->is_packed()) { 774 if (descriptor_->is_packed()) {
776 // We invoke getSerializedSize in writeTo for messages that have packed 775 // We invoke getSerializedSize in writeTo for messages that have packed
777 // fields in ImmutableMessageGenerator::GenerateMessageSerializationMethods. 776 // fields in ImmutableMessageGenerator::GenerateMessageSerializationMethods.
778 // That makes it safe to rely on the memoized size here. 777 // That makes it safe to rely on the memoized size here.
779 printer->Print(variables_, 778 printer->Print(variables_,
780 "if (get$capitalized_name$List().size() > 0) {\n" 779 "if (get$capitalized_name$List().size() > 0) {\n"
781 " output.writeUInt32NoTag($tag$);\n" 780 " output.writeRawVarint32($tag$);\n"
782 " output.writeUInt32NoTag($name$MemoizedSerializedSize);\n" 781 " output.writeRawVarint32($name$MemoizedSerializedSize);\n"
783 "}\n" 782 "}\n"
784 "for (int i = 0; i < $name$_.size(); i++) {\n" 783 "for (int i = 0; i < $name$_.size(); i++) {\n"
785 " output.write$capitalized_type$NoTag($name$_.get(i));\n" 784 " output.write$capitalized_type$NoTag($name$_.get(i));\n"
786 "}\n"); 785 "}\n");
787 } else { 786 } else {
788 printer->Print(variables_, 787 printer->Print(variables_,
789 "for (int i = 0; i < $name$_.size(); i++) {\n" 788 "for (int i = 0; i < $name$_.size(); i++) {\n"
790 " output.write$capitalized_type$($number$, $name$_.get(i));\n" 789 " output.write$capitalized_type$($number$, $name$_.get(i));\n"
791 "}\n"); 790 "}\n");
792 } 791 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 } 851 }
853 852
854 string RepeatedImmutablePrimitiveFieldGenerator::GetBoxedType() const { 853 string RepeatedImmutablePrimitiveFieldGenerator::GetBoxedType() const {
855 return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); 854 return BoxedPrimitiveTypeName(GetJavaType(descriptor_));
856 } 855 }
857 856
858 } // namespace java 857 } // namespace java
859 } // namespace compiler 858 } // namespace compiler
860 } // namespace protobuf 859 } // namespace protobuf
861 } // namespace google 860 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698