From 083e3e38e6c7b850f8f930e168d6099c5057ed43 Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Tue, 23 Jan 2024 12:15:10 -0800 Subject: [PATCH] Strip nonfunctional codegen diff from line number in Javadoc comment for deprecated fields, which may shift after adding features post-Editions transform PiperOrigin-RevId: 600868515 --- src/google/protobuf/compiler/java/doc_comment.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/google/protobuf/compiler/java/doc_comment.cc b/src/google/protobuf/compiler/java/doc_comment.cc index 992cc97100..3047dd4bdb 100644 --- a/src/google/protobuf/compiler/java/doc_comment.cc +++ b/src/google/protobuf/compiler/java/doc_comment.cc @@ -234,7 +234,8 @@ void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field, } void WriteDeprecatedJavadoc(io::Printer* printer, const FieldDescriptor* field, - const FieldAccessorType type) { + const FieldAccessorType type, + const Options options) { if (!field->options().deprecated()) { return; } @@ -253,8 +254,10 @@ void WriteDeprecatedJavadoc(io::Printer* printer, const FieldDescriptor* field, printer->Print(" * @deprecated $name$ is deprecated.\n", "name", field->full_name()); - printer->Print(" * See $file$;l=$line$\n", "file", field->file()->name(), - "line", startLine); + if (!options.strip_nonfunctional_codegen) { + printer->Print(" * See $file$;l=$line$\n", "file", + field->file()->name(), "line", startLine); + } } void WriteFieldAccessorDocComment(io::Printer* printer, @@ -265,7 +268,7 @@ void WriteFieldAccessorDocComment(io::Printer* printer, printer->Print("/**\n"); WriteDocCommentBody(printer, field, kdoc); WriteDebugString(printer, field, options, kdoc); - if (!kdoc) WriteDeprecatedJavadoc(printer, field, type); + if (!kdoc) WriteDeprecatedJavadoc(printer, field, type, options); switch (type) { case HAZZER: printer->Print(" * @return Whether the $name$ field is set.\n", "name", @@ -325,7 +328,7 @@ void WriteFieldEnumValueAccessorDocComment(io::Printer* printer, printer->Print("/**\n"); WriteDocCommentBody(printer, field, kdoc); WriteDebugString(printer, field, options, kdoc); - if (!kdoc) WriteDeprecatedJavadoc(printer, field, type); + if (!kdoc) WriteDeprecatedJavadoc(printer, field, type, options); switch (type) { case HAZZER: // Should never happen @@ -396,7 +399,7 @@ void WriteFieldStringBytesAccessorDocComment(io::Printer* printer, printer->Print("/**\n"); WriteDocCommentBody(printer, field, kdoc); WriteDebugString(printer, field, options, kdoc); - if (!kdoc) WriteDeprecatedJavadoc(printer, field, type); + if (!kdoc) WriteDeprecatedJavadoc(printer, field, type, options); switch (type) { case HAZZER: // Should never happen