Commit 4014b9f8 authored by temporal's avatar temporal

Add @Override annotation to generated Java code where appropriate.

Patch from Brian Atkinson <nairb774@gmail.com>.
parent bf86b546
...@@ -47,3 +47,5 @@ Non-Google patch contributors: ...@@ -47,3 +47,5 @@ Non-Google patch contributors:
Dilip Joseph <dilip.antony.joseph@gmail.com> Dilip Joseph <dilip.antony.joseph@gmail.com>
* Heuristic detection of sub-messages when printing unknown fields in * Heuristic detection of sub-messages when printing unknown fields in
text format. text format.
Brian Atkinson <nairb774@gmail.com>
* Added @Override annotation to generated Java code where appropriate.
...@@ -241,6 +241,7 @@ void MessageGenerator::Generate(io::Printer* printer) { ...@@ -241,6 +241,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
" return $fileclass$.internal_$identifier$_descriptor;\n" " return $fileclass$.internal_$identifier$_descriptor;\n"
"}\n" "}\n"
"\n" "\n"
"@Override\n"
"protected com.google.protobuf.GeneratedMessage.FieldAccessorTable\n" "protected com.google.protobuf.GeneratedMessage.FieldAccessorTable\n"
" internalGetFieldAccessorTable() {\n" " internalGetFieldAccessorTable() {\n"
" return $fileclass$.internal_$identifier$_fieldAccessorTable;\n" " return $fileclass$.internal_$identifier$_fieldAccessorTable;\n"
...@@ -293,6 +294,7 @@ GenerateMessageSerializationMethods(io::Printer* printer) { ...@@ -293,6 +294,7 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
ExtensionRangeOrdering()); ExtensionRangeOrdering());
printer->Print( printer->Print(
"@Override\n"
"public void writeTo(com.google.protobuf.CodedOutputStream output)\n" "public void writeTo(com.google.protobuf.CodedOutputStream output)\n"
" throws java.io.IOException {\n"); " throws java.io.IOException {\n");
printer->Indent(); printer->Indent();
...@@ -331,6 +333,7 @@ GenerateMessageSerializationMethods(io::Printer* printer) { ...@@ -331,6 +333,7 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
"}\n" "}\n"
"\n" "\n"
"private int memoizedSerializedSize = -1;\n" "private int memoizedSerializedSize = -1;\n"
"@Override\n"
"public int getSerializedSize() {\n" "public int getSerializedSize() {\n"
" int size = memoizedSerializedSize;\n" " int size = memoizedSerializedSize;\n"
" if (size != -1) return size;\n" " if (size != -1) return size;\n"
...@@ -485,19 +488,23 @@ void MessageGenerator::GenerateCommonBuilderMethods(io::Printer* printer) { ...@@ -485,19 +488,23 @@ void MessageGenerator::GenerateCommonBuilderMethods(io::Printer* printer) {
"\n" "\n"
"$classname$ result = new $classname$();\n" "$classname$ result = new $classname$();\n"
"\n" "\n"
"@Override\n"
"protected $classname$ internalGetResult() {\n" "protected $classname$ internalGetResult() {\n"
" return result;\n" " return result;\n"
"}\n" "}\n"
"\n" "\n"
"@Override\n"
"public Builder clear() {\n" "public Builder clear() {\n"
" result = new $classname$();\n" " result = new $classname$();\n"
" return this;\n" " return this;\n"
"}\n" "}\n"
"\n" "\n"
"@Override\n"
"public Builder clone() {\n" "public Builder clone() {\n"
" return new Builder().mergeFrom(result);\n" " return new Builder().mergeFrom(result);\n"
"}\n" "}\n"
"\n" "\n"
"@Override\n"
"public com.google.protobuf.Descriptors.Descriptor\n" "public com.google.protobuf.Descriptors.Descriptor\n"
" getDescriptorForType() {\n" " getDescriptorForType() {\n"
" return $classname$.getDescriptor();\n" " return $classname$.getDescriptor();\n"
...@@ -550,6 +557,7 @@ void MessageGenerator::GenerateCommonBuilderMethods(io::Printer* printer) { ...@@ -550,6 +557,7 @@ void MessageGenerator::GenerateCommonBuilderMethods(io::Printer* printer) {
if (descriptor_->file()->options().optimize_for() == FileOptions::SPEED) { if (descriptor_->file()->options().optimize_for() == FileOptions::SPEED) {
printer->Print( printer->Print(
"@Override\n"
"public Builder mergeFrom(com.google.protobuf.Message other) {\n" "public Builder mergeFrom(com.google.protobuf.Message other) {\n"
" if (other instanceof $classname$) {\n" " if (other instanceof $classname$) {\n"
" return mergeFrom(($classname$)other);\n" " return mergeFrom(($classname$)other);\n"
...@@ -586,6 +594,7 @@ void MessageGenerator::GenerateBuilderParsingMethods(io::Printer* printer) { ...@@ -586,6 +594,7 @@ void MessageGenerator::GenerateBuilderParsingMethods(io::Printer* printer) {
SortFieldsByNumber(descriptor_)); SortFieldsByNumber(descriptor_));
printer->Print( printer->Print(
"@Override\n"
"public Builder mergeFrom(\n" "public Builder mergeFrom(\n"
" com.google.protobuf.CodedInputStream input)\n" " com.google.protobuf.CodedInputStream input)\n"
" throws java.io.IOException {\n" " throws java.io.IOException {\n"
...@@ -593,6 +602,7 @@ void MessageGenerator::GenerateBuilderParsingMethods(io::Printer* printer) { ...@@ -593,6 +602,7 @@ void MessageGenerator::GenerateBuilderParsingMethods(io::Printer* printer) {
" com.google.protobuf.ExtensionRegistry.getEmptyRegistry());\n" " com.google.protobuf.ExtensionRegistry.getEmptyRegistry());\n"
"}\n" "}\n"
"\n" "\n"
"@Override\n"
"public Builder mergeFrom(\n" "public Builder mergeFrom(\n"
" com.google.protobuf.CodedInputStream input,\n" " com.google.protobuf.CodedInputStream input,\n"
" com.google.protobuf.ExtensionRegistry extensionRegistry)\n" " com.google.protobuf.ExtensionRegistry extensionRegistry)\n"
...@@ -656,6 +666,7 @@ void MessageGenerator::GenerateBuilderParsingMethods(io::Printer* printer) { ...@@ -656,6 +666,7 @@ void MessageGenerator::GenerateBuilderParsingMethods(io::Printer* printer) {
void MessageGenerator::GenerateIsInitialized(io::Printer* printer) { void MessageGenerator::GenerateIsInitialized(io::Printer* printer) {
printer->Print( printer->Print(
"@Override\n"
"public final boolean isInitialized() {\n"); "public final boolean isInitialized() {\n");
printer->Indent(); printer->Indent();
......
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