From 4014b9f83f612cd6ca4348b0d2ca9974d44e671d Mon Sep 17 00:00:00 2001 From: temporal Date: Wed, 17 Sep 2008 02:41:14 +0000 Subject: [PATCH] Add @Override annotation to generated Java code where appropriate. Patch from Brian Atkinson . --- CONTRIBUTORS.txt | 2 ++ src/google/protobuf/compiler/java/java_message.cc | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index a22cda45d7..21c83c6694 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -47,3 +47,5 @@ Non-Google patch contributors: Dilip Joseph * Heuristic detection of sub-messages when printing unknown fields in text format. + Brian Atkinson + * Added @Override annotation to generated Java code where appropriate. diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc index ebba1f7bc1..8e7437f8c3 100644 --- a/src/google/protobuf/compiler/java/java_message.cc +++ b/src/google/protobuf/compiler/java/java_message.cc @@ -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();