Commit c6120749 authored by Jie Luo's avatar Jie Luo

sync the Manually integrate changes in google3/third_party

parent 2850a982
...@@ -158,6 +158,10 @@ void EnumGenerator::Generate(io::Printer* printer) { ...@@ -158,6 +158,10 @@ void EnumGenerator::Generate(io::Printer* printer) {
"}\n" "}\n"
"\n" "\n"
"public static $classname$ valueOf(int value) {\n" "public static $classname$ valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n"
"public static $classname$ forNumber(int value) {\n"
" switch (value) {\n", " switch (value) {\n",
"classname", descriptor_->name()); "classname", descriptor_->name());
printer->Indent(); printer->Indent();
...@@ -185,7 +189,7 @@ void EnumGenerator::Generate(io::Printer* printer) { ...@@ -185,7 +189,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
" $classname$> internalValueMap =\n" " $classname$> internalValueMap =\n"
" new com.google.protobuf.Internal.EnumLiteMap<$classname$>() {\n" " new com.google.protobuf.Internal.EnumLiteMap<$classname$>() {\n"
" public $classname$ findValueByNumber(int number) {\n" " public $classname$ findValueByNumber(int number) {\n"
" return $classname$.valueOf(number);\n" " return $classname$.forNumber(number);\n"
" }\n" " }\n"
" };\n" " };\n"
"\n", "\n",
......
...@@ -198,7 +198,7 @@ GenerateMembers(io::Printer* printer) const { ...@@ -198,7 +198,7 @@ GenerateMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_); WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_, printer->Print(variables_,
"$deprecation$public $type$ get$capitalized_name$() {\n" "$deprecation$public $type$ get$capitalized_name$() {\n"
" $type$ result = $type$.valueOf($name$_);\n" " $type$ result = $type$.forNumber($name$_);\n"
" return result == null ? $unknown$ : result;\n" " return result == null ? $unknown$ : result;\n"
"}\n"); "}\n");
} }
...@@ -231,7 +231,7 @@ GenerateBuilderMembers(io::Printer* printer) const { ...@@ -231,7 +231,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_); WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_, printer->Print(variables_,
"$deprecation$public $type$ get$capitalized_name$() {\n" "$deprecation$public $type$ get$capitalized_name$() {\n"
" $type$ result = $type$.valueOf($name$_);\n" " $type$ result = $type$.forNumber($name$_);\n"
" return result == null ? $unknown$ : result;\n" " return result == null ? $unknown$ : result;\n"
"}\n"); "}\n");
WriteFieldDocComment(printer, descriptor_); WriteFieldDocComment(printer, descriptor_);
...@@ -311,7 +311,7 @@ GenerateParsingCode(io::Printer* printer) const { ...@@ -311,7 +311,7 @@ GenerateParsingCode(io::Printer* printer) const {
} else { } else {
printer->Print(variables_, printer->Print(variables_,
"int rawValue = input.readEnum();\n" "int rawValue = input.readEnum();\n"
"$type$ value = $type$.valueOf(rawValue);\n" "$type$ value = $type$.forNumber(rawValue);\n"
"if (value == null) {\n"); "if (value == null) {\n");
if (PreserveUnknownFields(descriptor_->containing_type())) { if (PreserveUnknownFields(descriptor_->containing_type())) {
printer->Print(variables_, printer->Print(variables_,
...@@ -405,7 +405,7 @@ GenerateMembers(io::Printer* printer) const { ...@@ -405,7 +405,7 @@ GenerateMembers(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"$deprecation$public $type$ get$capitalized_name$() {\n" "$deprecation$public $type$ get$capitalized_name$() {\n"
" if ($has_oneof_case_message$) {\n" " if ($has_oneof_case_message$) {\n"
" $type$ result = $type$.valueOf((java.lang.Integer) $oneof_name$_);\n" " $type$ result = $type$.forNumber((java.lang.Integer) $oneof_name$_);\n"
" return result == null ? $unknown$ : result;\n" " return result == null ? $unknown$ : result;\n"
" }\n" " }\n"
" return $default$;\n" " return $default$;\n"
...@@ -443,7 +443,7 @@ GenerateBuilderMembers(io::Printer* printer) const { ...@@ -443,7 +443,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"$deprecation$public $type$ get$capitalized_name$() {\n" "$deprecation$public $type$ get$capitalized_name$() {\n"
" if ($has_oneof_case_message$) {\n" " if ($has_oneof_case_message$) {\n"
" $type$ result = $type$.valueOf((java.lang.Integer) $oneof_name$_);\n" " $type$ result = $type$.forNumber((java.lang.Integer) $oneof_name$_);\n"
" return result == null ? $unknown$ : result;\n" " return result == null ? $unknown$ : result;\n"
" }\n" " }\n"
" return $default$;\n" " return $default$;\n"
...@@ -500,7 +500,7 @@ GenerateParsingCode(io::Printer* printer) const { ...@@ -500,7 +500,7 @@ GenerateParsingCode(io::Printer* printer) const {
} else { } else {
printer->Print(variables_, printer->Print(variables_,
"int rawValue = input.readEnum();\n" "int rawValue = input.readEnum();\n"
"$type$ value = $type$.valueOf(rawValue);\n" "$type$ value = $type$.forNumber(rawValue);\n"
"if (value == null) {\n"); "if (value == null) {\n");
if (PreserveUnknownFields(descriptor_->containing_type())) { if (PreserveUnknownFields(descriptor_->containing_type())) {
printer->Print(variables_, printer->Print(variables_,
...@@ -613,7 +613,7 @@ GenerateMembers(io::Printer* printer) const { ...@@ -613,7 +613,7 @@ GenerateMembers(io::Printer* printer) const {
" new com.google.protobuf.Internal.ListAdapter.Converter<\n" " new com.google.protobuf.Internal.ListAdapter.Converter<\n"
" java.lang.Integer, $type$>() {\n" " java.lang.Integer, $type$>() {\n"
" public $type$ convert(java.lang.Integer from) {\n" " public $type$ convert(java.lang.Integer from) {\n"
" $type$ result = $type$.valueOf(from);\n" " $type$ result = $type$.forNumber(from);\n"
" return result == null ? $unknown$ : result;\n" " return result == null ? $unknown$ : result;\n"
" }\n" " }\n"
" };\n"); " };\n");
...@@ -846,7 +846,7 @@ GenerateParsingCode(io::Printer* printer) const { ...@@ -846,7 +846,7 @@ GenerateParsingCode(io::Printer* printer) const {
} else { } else {
printer->Print(variables_, printer->Print(variables_,
"int rawValue = input.readEnum();\n" "int rawValue = input.readEnum();\n"
"$type$ value = $type$.valueOf(rawValue);\n" "$type$ value = $type$.forNumber(rawValue);\n"
"if (value == null) {\n"); "if (value == null) {\n");
if (PreserveUnknownFields(descriptor_->containing_type())) { if (PreserveUnknownFields(descriptor_->containing_type())) {
printer->Print(variables_, printer->Print(variables_,
......
...@@ -179,7 +179,7 @@ GenerateMembers(io::Printer* printer) const { ...@@ -179,7 +179,7 @@ GenerateMembers(io::Printer* printer) const {
WriteFieldDocComment(printer, descriptor_); WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_, printer->Print(variables_,
"$deprecation$public $type$ get$capitalized_name$() {\n" "$deprecation$public $type$ get$capitalized_name$() {\n"
" $type$ result = $type$.valueOf($name$_);\n" " $type$ result = $type$.forNumber($name$_);\n"
" return result == null ? $unknown$ : result;\n" " return result == null ? $unknown$ : result;\n"
"}\n"); "}\n");
...@@ -295,7 +295,7 @@ GenerateParsingCode(io::Printer* printer) const { ...@@ -295,7 +295,7 @@ GenerateParsingCode(io::Printer* printer) const {
} else { } else {
printer->Print(variables_, printer->Print(variables_,
"int rawValue = input.readEnum();\n" "int rawValue = input.readEnum();\n"
"$type$ value = $type$.valueOf(rawValue);\n" "$type$ value = $type$.forNumber(rawValue);\n"
"if (value == null) {\n"); "if (value == null) {\n");
if (PreserveUnknownFields(descriptor_->containing_type())) { if (PreserveUnknownFields(descriptor_->containing_type())) {
printer->Print(variables_, printer->Print(variables_,
...@@ -389,7 +389,7 @@ GenerateMembers(io::Printer* printer) const { ...@@ -389,7 +389,7 @@ GenerateMembers(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"$deprecation$public $type$ get$capitalized_name$() {\n" "$deprecation$public $type$ get$capitalized_name$() {\n"
" if ($has_oneof_case_message$) {\n" " if ($has_oneof_case_message$) {\n"
" $type$ result = $type$.valueOf((java.lang.Integer) $oneof_name$_);\n" " $type$ result = $type$.forNumber((java.lang.Integer) $oneof_name$_);\n"
" return result == null ? $unknown$ : result;\n" " return result == null ? $unknown$ : result;\n"
" }\n" " }\n"
" return $default$;\n" " return $default$;\n"
...@@ -488,7 +488,7 @@ GenerateParsingCode(io::Printer* printer) const { ...@@ -488,7 +488,7 @@ GenerateParsingCode(io::Printer* printer) const {
} else { } else {
printer->Print(variables_, printer->Print(variables_,
"int rawValue = input.readEnum();\n" "int rawValue = input.readEnum();\n"
"$type$ value = $type$.valueOf(rawValue);\n" "$type$ value = $type$.forNumber(rawValue);\n"
"if (value == null) {\n"); "if (value == null) {\n");
if (PreserveUnknownFields(descriptor_->containing_type())) { if (PreserveUnknownFields(descriptor_->containing_type())) {
printer->Print(variables_, printer->Print(variables_,
...@@ -604,7 +604,7 @@ GenerateMembers(io::Printer* printer) const { ...@@ -604,7 +604,7 @@ GenerateMembers(io::Printer* printer) const {
" new com.google.protobuf.Internal.ListAdapter.Converter<\n" " new com.google.protobuf.Internal.ListAdapter.Converter<\n"
" java.lang.Integer, $type$>() {\n" " java.lang.Integer, $type$>() {\n"
" public $type$ convert(java.lang.Integer from) {\n" " public $type$ convert(java.lang.Integer from) {\n"
" $type$ result = $type$.valueOf(from);\n" " $type$ result = $type$.forNumber(from);\n"
" return result == null ? $unknown$ : result;\n" " return result == null ? $unknown$ : result;\n"
" }\n" " }\n"
" };\n"); " };\n");
...@@ -846,7 +846,7 @@ GenerateParsingCode(io::Printer* printer) const { ...@@ -846,7 +846,7 @@ GenerateParsingCode(io::Printer* printer) const {
} else { } else {
printer->Print(variables_, printer->Print(variables_,
"int rawValue = input.readEnum();\n" "int rawValue = input.readEnum();\n"
"$type$ value = $type$.valueOf(rawValue);\n" "$type$ value = $type$.forNumber(rawValue);\n"
"if (value == null) {\n"); "if (value == null) {\n");
if (PreserveUnknownFields(descriptor_->containing_type())) { if (PreserveUnknownFields(descriptor_->containing_type())) {
printer->Print(variables_, printer->Print(variables_,
......
...@@ -158,6 +158,10 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { ...@@ -158,6 +158,10 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
"}\n" "}\n"
"\n" "\n"
"public static $classname$ valueOf(int value) {\n" "public static $classname$ valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n"
"public static $classname$ forNumber(int value) {\n"
" switch (value) {\n", " switch (value) {\n",
"classname", descriptor_->name()); "classname", descriptor_->name());
printer->Indent(); printer->Indent();
...@@ -185,7 +189,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { ...@@ -185,7 +189,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
" $classname$> internalValueMap =\n" " $classname$> internalValueMap =\n"
" new com.google.protobuf.Internal.EnumLiteMap<$classname$>() {\n" " new com.google.protobuf.Internal.EnumLiteMap<$classname$>() {\n"
" public $classname$ findValueByNumber(int number) {\n" " public $classname$ findValueByNumber(int number) {\n"
" return $classname$.valueOf(number);\n" " return $classname$.forNumber(number);\n"
" }\n" " }\n"
" };\n" " };\n"
"\n", "\n",
......
...@@ -414,6 +414,10 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { ...@@ -414,6 +414,10 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
"}\n"); "}\n");
printer->Print(vars, printer->Print(vars,
"public static $oneof_capitalized_name$Case valueOf(int value) {\n" "public static $oneof_capitalized_name$Case valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n"
"public static $oneof_capitalized_name$Case forNumber(int value) {\n"
" switch (value) {\n"); " switch (value) {\n");
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) { for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j); const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
...@@ -440,7 +444,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { ...@@ -440,7 +444,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
printer->Print(vars, printer->Print(vars,
"public $oneof_capitalized_name$Case\n" "public $oneof_capitalized_name$Case\n"
"get$oneof_capitalized_name$Case() {\n" "get$oneof_capitalized_name$Case() {\n"
" return $oneof_capitalized_name$Case.valueOf(\n" " return $oneof_capitalized_name$Case.forNumber(\n"
" $oneof_name$Case_);\n" " $oneof_name$Case_);\n"
"}\n" "}\n"
"\n"); "\n");
......
...@@ -134,7 +134,7 @@ Generate(io::Printer* printer) { ...@@ -134,7 +134,7 @@ Generate(io::Printer* printer) {
printer->Print(vars, printer->Print(vars,
"public $oneof_capitalized_name$Case\n" "public $oneof_capitalized_name$Case\n"
" get$oneof_capitalized_name$Case() {\n" " get$oneof_capitalized_name$Case() {\n"
" return $oneof_capitalized_name$Case.valueOf(\n" " return $oneof_capitalized_name$Case.forNumber(\n"
" $oneof_name$Case_);\n" " $oneof_name$Case_);\n"
"}\n" "}\n"
"\n" "\n"
......
...@@ -265,6 +265,10 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { ...@@ -265,6 +265,10 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
"}\n"); "}\n");
printer->Print(vars, printer->Print(vars,
"public static $oneof_capitalized_name$Case valueOf(int value) {\n" "public static $oneof_capitalized_name$Case valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n"
"public static $oneof_capitalized_name$Case forNumber(int value) {\n"
" switch (value) {\n"); " switch (value) {\n");
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) { for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j); const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
...@@ -291,7 +295,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { ...@@ -291,7 +295,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
printer->Print(vars, printer->Print(vars,
"public $oneof_capitalized_name$Case\n" "public $oneof_capitalized_name$Case\n"
"get$oneof_capitalized_name$Case() {\n" "get$oneof_capitalized_name$Case() {\n"
" return $oneof_capitalized_name$Case.valueOf(\n" " return $oneof_capitalized_name$Case.forNumber(\n"
" $oneof_name$Case_);\n" " $oneof_name$Case_);\n"
"}\n" "}\n"
"\n" "\n"
......
...@@ -253,6 +253,12 @@ class DynamicMessage : public Message { ...@@ -253,6 +253,12 @@ class DynamicMessage : public Message {
DynamicMessage(const TypeInfo* type_info); DynamicMessage(const TypeInfo* type_info);
~DynamicMessage(); ~DynamicMessage();
#ifndef _MSC_VER
void operator delete(void *p) {
::operator delete(p); // non-sized deallocation
}
#endif
// Called on the prototype after construction to initialize message fields. // Called on the prototype after construction to initialize message fields.
void CrossLinkPrototypes(); void CrossLinkPrototypes();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment