Add @Override annotation to generated Java code where appropriate.

Patch from Brian Atkinson <nairb774@gmail.com>.
pull/3335/head
temporal 16 years ago
parent bf86b546c3
commit 4014b9f83f
  1. 2
      CONTRIBUTORS.txt
  2. 11
      src/google/protobuf/compiler/java/java_message.cc

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

Loading…
Cancel
Save