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

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

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component 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 map<string, string>* variables) { 64 std::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"] = SimpleItoa(WireFormat::MakeTag(descriptor)); 78 (*variables)["tag"] =
79 SimpleItoa(static_cast<int32>(WireFormat::MakeTag(descriptor)));
79 (*variables)["tag_size"] = SimpleItoa( 80 (*variables)["tag_size"] = SimpleItoa(
80 WireFormat::TagSize(descriptor->number(), GetType(descriptor))); 81 WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
81 if (IsReferenceType(GetJavaType(descriptor))) { 82 if (IsReferenceType(GetJavaType(descriptor))) {
82 (*variables)["null_check"] = 83 (*variables)["null_check"] =
83 " if (value == null) {\n" 84 " if (value == null) {\n"
84 " throw new NullPointerException();\n" 85 " throw new NullPointerException();\n"
85 " }\n"; 86 " }\n";
86 } else { 87 } else {
87 (*variables)["null_check"] = ""; 88 (*variables)["null_check"] = "";
88 } 89 }
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 } 771 }
771 772
772 void RepeatedImmutablePrimitiveFieldGenerator:: 773 void RepeatedImmutablePrimitiveFieldGenerator::
773 GenerateSerializationCode(io::Printer* printer) const { 774 GenerateSerializationCode(io::Printer* printer) const {
774 if (descriptor_->is_packed()) { 775 if (descriptor_->is_packed()) {
775 // We invoke getSerializedSize in writeTo for messages that have packed 776 // We invoke getSerializedSize in writeTo for messages that have packed
776 // fields in ImmutableMessageGenerator::GenerateMessageSerializationMethods. 777 // fields in ImmutableMessageGenerator::GenerateMessageSerializationMethods.
777 // That makes it safe to rely on the memoized size here. 778 // That makes it safe to rely on the memoized size here.
778 printer->Print(variables_, 779 printer->Print(variables_,
779 "if (get$capitalized_name$List().size() > 0) {\n" 780 "if (get$capitalized_name$List().size() > 0) {\n"
780 " output.writeRawVarint32($tag$);\n" 781 " output.writeUInt32NoTag($tag$);\n"
781 " output.writeRawVarint32($name$MemoizedSerializedSize);\n" 782 " output.writeUInt32NoTag($name$MemoizedSerializedSize);\n"
782 "}\n" 783 "}\n"
783 "for (int i = 0; i < $name$_.size(); i++) {\n" 784 "for (int i = 0; i < $name$_.size(); i++) {\n"
784 " output.write$capitalized_type$NoTag($name$_.get(i));\n" 785 " output.write$capitalized_type$NoTag($name$_.get(i));\n"
785 "}\n"); 786 "}\n");
786 } else { 787 } else {
787 printer->Print(variables_, 788 printer->Print(variables_,
788 "for (int i = 0; i < $name$_.size(); i++) {\n" 789 "for (int i = 0; i < $name$_.size(); i++) {\n"
789 " output.write$capitalized_type$($number$, $name$_.get(i));\n" 790 " output.write$capitalized_type$($number$, $name$_.get(i));\n"
790 "}\n"); 791 "}\n");
791 } 792 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 } 852 }
852 853
853 string RepeatedImmutablePrimitiveFieldGenerator::GetBoxedType() const { 854 string RepeatedImmutablePrimitiveFieldGenerator::GetBoxedType() const {
854 return BoxedPrimitiveTypeName(GetJavaType(descriptor_)); 855 return BoxedPrimitiveTypeName(GetJavaType(descriptor_));
855 } 856 }
856 857
857 } // namespace java 858 } // namespace java
858 } // namespace compiler 859 } // namespace compiler
859 } // namespace protobuf 860 } // namespace protobuf
860 } // namespace google 861 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698