ProtoAnnotatorPlugin

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 {
}

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.
}

And generated gPRC service like:


// Annotation goes here.
public class ServiceGrpc {
     // ...
}

For MessageOptions:


import "spine/options.proto";

message Message {
     option (experimental_type) = true;
}

Will annotate generated file like:


OuterClassName {

     // Annotation goes here.
     public static final class Message ...

     // Annotation goes here.
     public interface MessageOrBuilder ...
}

For ServiceOptions:


import "spine/options.proto";

service Service {
     option (SPI_service) = true;
}

Will annotate generated gRPC service like:


// Annotation goes here.
ServiceGrpc {
     // ...
}

For FieldOptions:


import "spine/options.proto";

message Message {
     string value = 1 [(experimental) = true] ;
}

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.
             }
     }
}

If java_multiple_files = true result of annotation will be similar.

Constructors

Link copied to clipboard
public void ProtoAnnotatorPlugin()

Functions

Link copied to clipboard
public void apply(Project project)