-
Notifications
You must be signed in to change notification settings - Fork 15.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java generator: mark all generated classes and interfaces with javax.annotation.Generated #42
Comments
it seems that there is already an option for this: --java_opt=annotate_code but it is not documented in the help text |
Annotating generated code is on our radar. There are several different proposals (for different use case) that we haven't reached consensus yet (e.g. whether to use custom annotations, whether to use runtime retention etc) |
I've just played around with the undocumented Obviously, it only works in proto3, and in the latest versions only (fails with protoc 3.1.0). That's fair enough though (especially as it is not officially supported). It looks like when the option is specified, only top-level classes and interfaces are being annotated.
I have also tried adding I hope the kind folks at Google are going to provide a bit more clarity in the due course. |
@sergei-ivanov I believe the option |
People seem to want this feature, I now I do. There is already the code to enable it. Why not make it public? |
@pherl what's the concern with adding |
There were several teams asking for annotations but with different requirement, e.g. runtime retention vs compile time retention; annotation with type information. All of those will affect how we should annotate the classes. There is also on-going experimental java runtime developement work that uses annotations. I think after the new runtime work is done, we can revisit the annotation issue. |
Adding
|
|
Yeah, in Java 9 there is a new annotation javax.annotation.processing But you can wait four more years before using it just in case something will be deprecated/removed from the classpath/whatever. |
@ejona86 My feeling is that with Java9 and beyond Oracle is going to become more aggressive in deprecating and removing classes from the core JDK. Now that they have a mechanism for that (modules and multiple version jars), there's no stopping them. Which probably means that the only choice for protobuf project is to introduce something like |
Is there an equivalent for javalite? I tried |
Would a PR for a different Proto option (maybe something like What would it take to get this feature in? |
I don't find For gRPC we ended up just continuing to use |
With the new version of Java lite, you can also use the annotate_code option like this: We will likely continue to use the |
The PHPDoc escaping in PHP is aggressive in that it escapes some character sequences that don't need to be escaped (`/*`), and it uses HTML entities to escape others (`*/` and `@`) instead of the recommended PHPDoc escape sequences. For Example, in [`Google\Api\RoutingParameter`](https://github.com/googleapis/common-protos-php/blob/main/src/Api/RoutingParameter.php#L42): ``` * path_template: "projects/*/{table_location=instances/*}/tables/*" ``` Should be escaped as: ``` * path_template: "projects/{@*}{table_location=instances/*}/tables/*" ``` according to [the PHPDoc guide](https://manual.phpdoc.org/HTMLframesConverter/default/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.desc): - For `@`: "if you need an actual "@" in your DocBlock's description parts, you should be careful to either ensure it is not the first character on a line, or else escape it ("\\@") to avoid it being interpreted as a PhpDocumentor tag marker." - For `*/`: " If you need to use the closing comment "\*/" in a DocBlock, use the special escape sequence "{@*}." Closes #11208 COPYBARA_INTEGRATE_REVIEW=#11208 from bshaffer:more-readable-phpdoc-escaping a75f974 FUTURE_COPYBARA_INTEGRATE_REVIEW=#11208 from bshaffer:more-readable-phpdoc-escaping a75f974 PiperOrigin-RevId: 602870442
The PHPDoc escaping in PHP is aggressive in that it escapes some character sequences that don't need to be escaped (`/*`), and it uses HTML entities to escape others (`*/` and `@`) instead of the recommended PHPDoc escape sequences. For Example, in [`Google\Api\RoutingParameter`](https://github.com/googleapis/common-protos-php/blob/main/src/Api/RoutingParameter.php#L42): ``` * path_template: "projects/*/{table_location=instances/*}/tables/*" ``` Should be escaped as: ``` * path_template: "projects/{@*}{table_location=instances/*}/tables/*" ``` according to [the PHPDoc guide](https://manual.phpdoc.org/HTMLframesConverter/default/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.desc): - For `@`: "if you need an actual "@" in your DocBlock's description parts, you should be careful to either ensure it is not the first character on a line, or else escape it ("\\@") to avoid it being interpreted as a PhpDocumentor tag marker." - For `*/`: " If you need to use the closing comment "\*/" in a DocBlock, use the special escape sequence "{@*}." Closes #11208 COPYBARA_INTEGRATE_REVIEW=#11208 from bshaffer:more-readable-phpdoc-escaping a75f974 PiperOrigin-RevId: 603091642
The PHPDoc escaping in PHP is aggressive in that it escapes some character sequences that don't need to be escaped (`/*`), and it uses HTML entities to escape others (`*/` and `@`) instead of the recommended PHPDoc escape sequences. For Example, in [`Google\Api\RoutingParameter`](https://github.com/googleapis/common-protos-php/blob/main/src/Api/RoutingParameter.php#L42): ``` * path_template: "projects/&protocolbuffers#42;&protocolbuffers#47;{table_location=instances/&protocolbuffers#42;}/tables/&protocolbuffers#42;" ``` Should be escaped as: ``` * path_template: "projects/{@*}{table_location=instances/*}/tables/*" ``` according to [the PHPDoc guide](https://manual.phpdoc.org/HTMLframesConverter/default/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.desc): - For `@`: "if you need an actual "@" in your DocBlock's description parts, you should be careful to either ensure it is not the first character on a line, or else escape it ("\\@") to avoid it being interpreted as a PhpDocumentor tag marker." - For `*/`: " If you need to use the closing comment "\*/" in a DocBlock, use the special escape sequence "{@*}." Closes protocolbuffers#11208 COPYBARA_INTEGRATE_REVIEW=protocolbuffers#11208 from bshaffer:more-readable-phpdoc-escaping a75f974 PiperOrigin-RevId: 603091642
javax.annotation.Generated
exists since Java 6 (relevant javadoc) so it should be safe to generate source code that contains it. The presence of this annotation has no impact on the runtime characteristics of the annotated classes.When this annotation is present it greatly helps in configuration of different tools related to code analysis, tests and tests coverage.
Both the outer Java class and all inner builder and message classes and interfaces should be annotated with
javax.annotation.Generated
.The text was updated successfully, but these errors were encountered: