Commit 800f65e2 authored by Jon Skeet's avatar Jon Skeet

Patch from Miguel de Icaza - tweaks to generated C#

parent 007f8596
...@@ -17,10 +17,10 @@ set -ex ...@@ -17,10 +17,10 @@ set -ex
rm -rf autom4te.cache rm -rf autom4te.cache
aclocal-1.9 --force -I m4 aclocal-1.10 --force -I m4
libtoolize -c -f libtoolize -c -f
autoheader -f -W all autoheader -f -W all
automake-1.9 --foreign -a -c -f -W all automake-1.10 --foreign -a -c -f -W all
autoconf -f -W all,no-obsolete autoconf -f -W all,no-obsolete
rm -rf autom4te.cache config.h.in~ rm -rf autom4te.cache config.h.in~
......
...@@ -70,25 +70,25 @@ GenerateMembers(io::Printer* printer) const { ...@@ -70,25 +70,25 @@ GenerateMembers(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"private boolean has$capitalized_name$;\r\n" "private boolean has$capitalized_name$;\r\n"
"private $type$ $name$_ = $default$;\r\n" "private $type$ $name$_ = $default$;\r\n"
"public boolean has$capitalized_name$() { return has$capitalized_name$; }\r\n" "public boolean Has$capitalized_name$() { return has$capitalized_name$; }\r\n"
"public $type$ get$capitalized_name$() { return $name$_; }\r\n"); "public $type$ Get$capitalized_name$() { return $name$_; }\r\n");
} }
void EnumFieldGenerator:: void EnumFieldGenerator::
GenerateBuilderMembers(io::Printer* printer) const { GenerateBuilderMembers(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"public boolean has$capitalized_name$() {\r\n" "public boolean Has$capitalized_name$() {\r\n"
" return result.has$capitalized_name$();\r\n" " return result.Has$capitalized_name$();\r\n"
"}\r\n" "}\r\n"
"public $type$ get$capitalized_name$() {\r\n" "public $type$ Get$capitalized_name$() {\r\n"
" return result.get$capitalized_name$();\r\n" " return result.Get$capitalized_name$();\r\n"
"}\r\n" "}\r\n"
"public Builder set$capitalized_name$($type$ value) {\r\n" "public Builder Set$capitalized_name$($type$ value) {\r\n"
" result.has$capitalized_name$ = true;\r\n" " result.has$capitalized_name$ = true;\r\n"
" result.$name$_ = value;\r\n" " result.$name$_ = value;\r\n"
" return this;\r\n" " return this;\r\n"
"}\r\n" "}\r\n"
"public Builder clear$capitalized_name$() {\r\n" "public Builder Clear$capitalized_name$() {\r\n"
" result.has$capitalized_name$ = false;\r\n" " result.has$capitalized_name$ = false;\r\n"
" result.$name$_ = $default$;\r\n" " result.$name$_ = $default$;\r\n"
" return this;\r\n" " return this;\r\n"
...@@ -154,15 +154,18 @@ RepeatedEnumFieldGenerator::~RepeatedEnumFieldGenerator() {} ...@@ -154,15 +154,18 @@ RepeatedEnumFieldGenerator::~RepeatedEnumFieldGenerator() {}
void RepeatedEnumFieldGenerator:: void RepeatedEnumFieldGenerator::
GenerateMembers(io::Printer* printer) const { GenerateMembers(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"private java.util.List<$type$> $name$_ =\r\n" "private System.Collections.Generic.List<$type$> $name$_ =\r\n"
" java.util.Collections.emptyList();\r\n" " new System.Collections.Generic.List<$type$> ();\r\n"
"public java.util.List<$type$> get$capitalized_name$List() {\r\n" "public System.Collections.Generic.List<$type$> $capitalized_name$List() {\r\n"
" return $name$_;\r\n" // note: unmodifiable list " return $name$_.AsReadOnly ();\r\n" // note: unmodifiable list
"}\r\n" "}\r\n"
"public int get$capitalized_name$Count() { return $name$_.size(); }\r\n"
"public $type$ get$capitalized_name$(int index) {\r\n" // Redundant API calls?
" return $name$_.get(index);\r\n" //"public int $capitalized_name$Count() { get { return $name$_.Count; } }\r\n"
"}\r\n"); //"public $type$ get$capitalized_name$(int index) {\r\n"
//" return $name$_.get(index);\r\n"
//"}\r\n"
);
} }
void RepeatedEnumFieldGenerator:: void RepeatedEnumFieldGenerator::
......
...@@ -63,7 +63,7 @@ void ExtensionGenerator::Generate(io::Printer* printer) { ...@@ -63,7 +63,7 @@ void ExtensionGenerator::Generate(io::Printer* printer) {
" pb::GeneratedMessage\r\n" " pb::GeneratedMessage\r\n"
" .newRepeatedGeneratedExtension(\r\n" " .newRepeatedGeneratedExtension(\r\n"
" getDescriptor().getExtensions().get($index$),\r\n" " getDescriptor().getExtensions().get($index$),\r\n"
" $type$.class);\r\n"); " typeof ($type$));\r\n");
} else { } else {
printer->Print(vars, printer->Print(vars,
"public static final\r\n" "public static final\r\n"
...@@ -72,7 +72,7 @@ void ExtensionGenerator::Generate(io::Printer* printer) { ...@@ -72,7 +72,7 @@ void ExtensionGenerator::Generate(io::Printer* printer) {
" $type$> $name$ =\r\n" " $type$> $name$ =\r\n"
" pb::GeneratedMessage.newGeneratedExtension(\r\n" " pb::GeneratedMessage.newGeneratedExtension(\r\n"
" getDescriptor().getExtensions().get($index$),\r\n" " getDescriptor().getExtensions().get($index$),\r\n"
" $type$.class);\r\n"); " typeof ($type$));\r\n");
} }
} }
......
...@@ -165,12 +165,12 @@ void MessageGenerator::GenerateStaticVariables(io::Printer* printer) { ...@@ -165,12 +165,12 @@ void MessageGenerator::GenerateStaticVariables(io::Printer* printer) {
// The descriptor for this type. // The descriptor for this type.
if (descriptor_->containing_type() == NULL) { if (descriptor_->containing_type() == NULL) {
printer->Print(vars, printer->Print(vars,
"$private$static readonly pb::Descriptors.Descriptor {\r\n" "$private$static readonly pb::Descriptors.Descriptor \r\n"
" internal_$identifier$_descriptor =\r\n" " internal_$identifier$_descriptor =\r\n"
" getDescriptor().getMessageTypes().get($index$);\r\n"); " getDescriptor().getMessageTypes().get($index$);\r\n");
} else { } else {
printer->Print(vars, printer->Print(vars,
"$private$static readonly pb::Descriptors.Descriptor {\r\n" "$private$static readonly pb::Descriptors.Descriptor \r\n"
" internal_$identifier$_descriptor =\r\n" " internal_$identifier$_descriptor =\r\n"
" internal_$parent$_descriptor.getNestedTypes().get($index$);\r\n"); " internal_$parent$_descriptor.getNestedTypes().get($index$);\r\n");
} }
...@@ -190,8 +190,8 @@ void MessageGenerator::GenerateStaticVariables(io::Printer* printer) { ...@@ -190,8 +190,8 @@ void MessageGenerator::GenerateStaticVariables(io::Printer* printer) {
UnderscoresToCapitalizedCamelCase(descriptor_->field(i))); UnderscoresToCapitalizedCamelCase(descriptor_->field(i)));
} }
printer->Print("},\r\n" printer->Print("},\r\n"
" $classname$.class,\r\n" " typeof ($classname$),\r\n"
" $classname$.Builder.class);\r\n", " typeof ($classname$.Builder));\r\n",
"classname", ClassName(descriptor_)); "classname", ClassName(descriptor_));
// Generate static members for all nested types. // Generate static members for all nested types.
......
...@@ -175,14 +175,15 @@ RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() {} ...@@ -175,14 +175,15 @@ RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() {}
void RepeatedMessageFieldGenerator:: void RepeatedMessageFieldGenerator::
GenerateMembers(io::Printer* printer) const { GenerateMembers(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"private java.util.List<$type$> $name$_ =\r\n" "internal System.Collections.Generic.IList<$type$> Empty$capitalized_name$ =\r\n"
" java.util.Collections.emptyList();\r\n" " new System.Collections.ReadOnlyCollection<$type$> ();\r\n"
"public java.util.List<$type$> get$capitalized_name$List() {\r\n" "internal System.Collections.Generic.IList<$type$> $name$_ = Empty$capitalized_name$;\r\n"
" return $name$_;\r\n" // note: unmodifiable list "public System.Collections.Generic.IList<$type$> $capitalized_name$List {\r\n"
" get { return $name$_; } \r\n" // note: unmodifiable list
"}\r\n" "}\r\n"
"public int get$capitalized_name$Count() { return $name$_.size(); }\r\n" "public int $capitalized_name$Count { get { return $name$_.Count; } }\r\n"
"public $type$ get$capitalized_name$(int index) {\r\n" "public $type$ $capitalized_name$(int index) {\r\n"
" return $name$_.get(index);\r\n" " return $name$_ [index];\r\n"
"}\r\n"); "}\r\n");
} }
...@@ -193,48 +194,47 @@ GenerateBuilderMembers(io::Printer* printer) const { ...@@ -193,48 +194,47 @@ GenerateBuilderMembers(io::Printer* printer) const {
// could hold on to the returned list and modify it after the message // could hold on to the returned list and modify it after the message
// has been built, thus mutating the message which is supposed to be // has been built, thus mutating the message which is supposed to be
// immutable. // immutable.
"public java.util.List<$type$> get$capitalized_name$List() {\r\n" "public System.Collections.Generic.IList<$type$> Get$capitalized_name$List() {\r\n"
" return java.util.Collections.unmodifiableList(result.$name$_);\r\n" " if (result.$name$_ == $type$.Empty$capitalized_name$)\r\n"
" return result.$name$;\r\n"
" return result.$name$_.AsReadOnly ();\r\n"
"}\r\n" "}\r\n"
"public int get$capitalized_name$Count() {\r\n" "public int Get$capitalized_name$Count() {\r\n"
" return result.get$capitalized_name$Count();\r\n" " return result.Get$capitalized_name$Count();\r\n"
"}\r\n" "}\r\n"
"public $type$ get$capitalized_name$(int index) {\r\n" "public $type$ Get$capitalized_name$(int index) {\r\n"
" return result.get$capitalized_name$(index);\r\n" " return result.Get$capitalized_name$(index);\r\n"
"}\r\n" "}\r\n"
"public Builder set$capitalized_name$(int index, $type$ value) {\r\n" "public Builder Set$capitalized_name$(int index, $type$ value) {\r\n"
" result.$name$_.set(index, value);\r\n" " result.$name$_ [index] = value;\r\n"
" return this;\r\n" " return this;\r\n"
"}\r\n" "}\r\n"
"public Builder set$capitalized_name$(int index, " "public Builder Set$capitalized_name$(int index, "
"$type$.Builder builderForValue) {\r\n" "$type$.Builder builderForValue) {\r\n"
" result.$name$_.set(index, builderForValue.build());\r\n" " result.$name$_ [index] = builderForValue.build();\r\n"
" return this;\r\n" " return this;\r\n"
"}\r\n" "}\r\n"
"public Builder add$capitalized_name$($type$ value) {\r\n" "public Builder Add$capitalized_name$($type$ value) {\r\n"
" if (result.$name$_.isEmpty()) {\r\n" " if (result.$name$ == $type$.Empty$capitalized_name$)\r\n"
" result.$name$_ = new java.util.ArrayList<$type$>();\r\n" " result.$name$ = new System.Collections.Generic.List<$type$>();\r\n"
" }\r\n" " result.$name$_.Add(value);\r\n"
" result.$name$_.add(value);\r\n"
" return this;\r\n" " return this;\r\n"
"}\r\n" "}\r\n"
"public Builder add$capitalized_name$($type$.Builder builderForValue) {\r\n" "public Builder Add$capitalized_name$($type$.Builder builderForValue) {\r\n"
" if (result.$name$_.isEmpty()) {\r\n" " if (result.$name$ == $type$.Empty$capitalized_name$)\r\n"
" result.$name$_ = new java.util.ArrayList<$type$>();\r\n" " result.$name$ = new System.Collections.Generic.List<$type$>();\r\n"
" }\r\n" " result.$name$_.Add(builderForValue.build());\r\n"
" result.$name$_.add(builderForValue.build());\r\n"
" return this;\r\n" " return this;\r\n"
"}\r\n" "}\r\n"
"public Builder addAll$capitalized_name$<T>(\r\n" "public Builder AddAll$capitalized_name$<T>(\r\n"
" global::System.Collections.Generic.IEnumerable<T> values) where T : $type$ {\r\n" " global::System.Collections.Generic.IEnumerable<T> values) where T : $type$ {\r\n"
" if (result.$name$_.isEmpty()) {\r\n" " if (result.$name$ == $type$.Empty$capitalized_name$)\r\n"
" result.$name$_ = new java.util.ArrayList<$type$>();\r\n" " result.$name$ = new System.Collections.Generic.List<$type$>();\r\n"
" }\r\n" " result.$name$_.AddEnumerable (values);\r\n"
" super.addAll(values, result.$name$_);\r\n"
" return this;\r\n" " return this;\r\n"
"}\r\n" "}\r\n"
"public Builder clear$capitalized_name$() {\r\n" "public Builder Clear$capitalized_name$() {\r\n"
" result.$name$_ = java.util.Collections.emptyList();\r\n" " result.$name$_ = $type$.Empty$capitalized_name$;\r\n"
" return this;\r\n" " return this;\r\n"
"}\r\n"); "}\r\n");
} }
...@@ -242,20 +242,20 @@ GenerateBuilderMembers(io::Printer* printer) const { ...@@ -242,20 +242,20 @@ GenerateBuilderMembers(io::Printer* printer) const {
void RepeatedMessageFieldGenerator:: void RepeatedMessageFieldGenerator::
GenerateMergingCode(io::Printer* printer) const { GenerateMergingCode(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"if (!other.$name$_.isEmpty()) {\r\n" "if (!other.$name$_ != $type$.Empty$capitalized_name$) {\r\n"
" if (result.$name$_.isEmpty()) {\r\n" " if (result.$name$_ == $type$.Empty$capitalized_name$) {\r\n"
" result.$name$_ = new java.util.ArrayList<$type$>();\r\n" " result.$name$_ = new System.Collections.Generic.List<$type$>();\r\n"
" }\r\n" " }\r\n"
" result.$name$_.addAll(other.$name$_);\r\n" " result.$name$_.AddCollection(other.$name$_);\r\n"
"}\r\n"); "}\r\n");
} }
void RepeatedMessageFieldGenerator:: void RepeatedMessageFieldGenerator::
GenerateBuildingCode(io::Printer* printer) const { GenerateBuildingCode(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"if (result.$name$_ != java.util.Collections.EMPTY_LIST) {\r\n" "if (result.$name$_ != $type$.Empty$capitalized_name$) {\r\n"
" result.$name$_ =\r\n" " result.$name$_ =\r\n"
" java.util.Collections.unmodifiableList(result.$name$_);\r\n" " result.$name$_.AsReadOnly ();\r\n"
"}\r\n"); "}\r\n");
} }
...@@ -273,13 +273,13 @@ GenerateParsingCode(io::Printer* printer) const { ...@@ -273,13 +273,13 @@ GenerateParsingCode(io::Printer* printer) const {
} }
printer->Print(variables_, printer->Print(variables_,
"add$capitalized_name$(subBuilder.buildPartial());\r\n"); "Add$capitalized_name$(subBuilder.buildPartial());\r\n");
} }
void RepeatedMessageFieldGenerator:: void RepeatedMessageFieldGenerator::
GenerateSerializationCode(io::Printer* printer) const { GenerateSerializationCode(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"for ($type$ element : get$capitalized_name$List()) {\r\n" "foreach ($type$ element in Get$capitalized_name$List()) {\r\n"
" output.write$group_or_message$($number$, element);\r\n" " output.write$group_or_message$($number$, element);\r\n"
"}\r\n"); "}\r\n");
} }
...@@ -287,7 +287,7 @@ GenerateSerializationCode(io::Printer* printer) const { ...@@ -287,7 +287,7 @@ GenerateSerializationCode(io::Printer* printer) const {
void RepeatedMessageFieldGenerator:: void RepeatedMessageFieldGenerator::
GenerateSerializedSizeCode(io::Printer* printer) const { GenerateSerializedSizeCode(io::Printer* printer) const {
printer->Print(variables_, printer->Print(variables_,
"for ($type$ element : get$capitalized_name$List()) {\r\n" "foreach ($type$ element in Get$capitalized_name$List()) {\r\n"
" size += pb::CodedOutputStream\r\n" " size += pb::CodedOutputStream\r\n"
" .compute$group_or_message$Size($number$, element);\r\n" " .compute$group_or_message$Size($number$, element);\r\n"
"}\r\n"); "}\r\n");
......
...@@ -102,12 +102,11 @@ string DefaultValue(const FieldDescriptor* field) { ...@@ -102,12 +102,11 @@ string DefaultValue(const FieldDescriptor* field) {
case FieldDescriptor::CPPTYPE_INT32: case FieldDescriptor::CPPTYPE_INT32:
return SimpleItoa(field->default_value_int32()); return SimpleItoa(field->default_value_int32());
case FieldDescriptor::CPPTYPE_UINT32: case FieldDescriptor::CPPTYPE_UINT32:
// Need to print as a signed int since Java has no unsigned. return SimpleItoa(field->default_value_uint32());
return SimpleItoa(static_cast<int32>(field->default_value_uint32()));
case FieldDescriptor::CPPTYPE_INT64: case FieldDescriptor::CPPTYPE_INT64:
return SimpleItoa(field->default_value_int64()) + "L"; return SimpleItoa(field->default_value_int64()) + "L";
case FieldDescriptor::CPPTYPE_UINT64: case FieldDescriptor::CPPTYPE_UINT64:
return SimpleItoa(static_cast<int64>(field->default_value_uint64())) + return SimpleItoa(field->default_value_uint64()) +
"L"; "L";
case FieldDescriptor::CPPTYPE_DOUBLE: case FieldDescriptor::CPPTYPE_DOUBLE:
return SimpleDtoa(field->default_value_double()) + "D"; return SimpleDtoa(field->default_value_double()) + "D";
......
...@@ -211,7 +211,7 @@ void ServiceGenerator::GenerateStub(io::Printer* printer) { ...@@ -211,7 +211,7 @@ void ServiceGenerator::GenerateStub(io::Printer* printer) {
" $output$.getDefaultInstance(),\r\n" " $output$.getDefaultInstance(),\r\n"
" pb::RpcUtil.generalizeCallback(\r\n" " pb::RpcUtil.generalizeCallback(\r\n"
" done,\r\n" " done,\r\n"
" $output$.class,\r\n" " typeof ($output$),\r\n"
" $output$.getDefaultInstance()));\r\n" " $output$.getDefaultInstance()));\r\n"
"}\r\n"); "}\r\n");
} }
......
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