Proto Annotator Plugin
A plugin that annotates generated Java sources from .proto
files.
Plugin annotates the Java sources depending on Protobuf option values.
To enable the Java sources annotation, apply the plugin to a Gradle project, and annotation will be built into Gradle build lifecycle, between Protobuf generation and Java compilation.
Examples:
For FileOptions
:
import "spine/options.proto";
option (experimental_all) = true;
message Message {
}
service Service {
}
Content copied to clipboard
Will annotate regular generated file like:
OuterClassName {
// Annotation goes here.
public static final class Message ...
// Annotation goes here.
public interface MessageOrBuilder ...
// And so on for every message and enum from a Protobuf file.
}
Content copied to clipboard
And generated gPRC service like:
// Annotation goes here.
public class ServiceGrpc {
// ...
}
Content copied to clipboard
For MessageOptions
:
import "spine/options.proto";
message Message {
option (experimental_type) = true;
}
Content copied to clipboard
Will annotate generated file like:
OuterClassName {
// Annotation goes here.
public static final class Message ...
// Annotation goes here.
public interface MessageOrBuilder ...
}
Content copied to clipboard
For ServiceOptions
:
import "spine/options.proto";
service Service {
option (SPI_service) = true;
}
Content copied to clipboard
Will annotate generated gRPC service like:
// Annotation goes here.
ServiceGrpc {
// ...
}
Content copied to clipboard
For FieldOptions
:
import "spine/options.proto";
message Message {
string value = 1 [(experimental) = true] ;
}
Content copied to clipboard
Will annotate generated file like:
OuterClassName {
public static final class Message ... {
// Annotation goes here.
public java.lang.String getEntityId() {
// ...
}
// And so on for every getter for the field.
public static final class Builder ... {
// Annotation goes here.
public java.lang.String getEntityId() {
// ...
}
// Annotation goes here.
public java.lang.String setEntityId() {
// ...
}
// And so on for every getter/setter for the field.
}
}
}
Content copied to clipboard
If java_multiple_files = true
result of annotation will be similar.