Skip to content

Commit 31e57fc

Browse files
acozzettecopybara-github
authored andcommitted
Introduce a Generated annotation to eventually replace javax.annotation.Generated
PiperOrigin-RevId: 741569920
1 parent 3396e5e commit 31e57fc

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

java/core/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ LITE_SRCS = [
4747
"src/main/java/com/google/protobuf/FieldSet.java",
4848
"src/main/java/com/google/protobuf/FieldType.java",
4949
"src/main/java/com/google/protobuf/FloatArrayList.java",
50+
"src/main/java/com/google/protobuf/Generated.java",
5051
"src/main/java/com/google/protobuf/GeneratedMessageInfoFactory.java",
5152
"src/main/java/com/google/protobuf/GeneratedMessageLite.java",
5253
"src/main/java/com/google/protobuf/InlineMe.java",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Protocol Buffers - Google's data interchange format
2+
// Copyright 2008 Google Inc. All rights reserved.
3+
//
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file or at
6+
// https://developers.google.com/open-source/licenses/bsd
7+
8+
package com.google.protobuf;
9+
10+
import static java.lang.annotation.ElementType.TYPE;
11+
import static java.lang.annotation.RetentionPolicy.SOURCE;
12+
13+
import java.lang.annotation.Documented;
14+
import java.lang.annotation.Retention;
15+
import java.lang.annotation.Target;
16+
17+
/** Marks protobuf implementations generated by the {@code protoc} compiler. */
18+
@Documented
19+
// This is only used for static analysis at the compilation level, so SOURCE retention is used. It
20+
// also must be SOURCE so that it does not force annotated classes to be forced into a main dex file
21+
// in Android apks.
22+
@Retention(SOURCE)
23+
@Target(TYPE)
24+
public @interface Generated {}

src/google/protobuf/compiler/java/helpers.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ const char kThinSeparator[] =
5353
void PrintGeneratedAnnotation(io::Printer* printer, char delimiter,
5454
absl::string_view annotation_file,
5555
Options options) {
56+
printer->Print("@com.google.protobuf.Generated\n");
57+
5658
if (annotation_file.empty()) {
5759
return;
5860
}
61+
// Print javax.annotation.Generated to support Kythe indexing
5962
std::string ptemplate =
6063
"@javax.annotation.Generated(value=\"protoc\", comments=\"annotations:";
6164
ptemplate.push_back(delimiter);

0 commit comments

Comments
 (0)