public abstract class ProtocPluginCodeGenerator
extends java.lang.Object
PluginProtos.CodeGeneratorRequest
2) Generating the code (extensions of this class control how this is actually done).
3) Writing out the PluginProtos.CodeGeneratorResponse.
The user of this class should implement the abstract methods and override the necessary
code generation methods, and then use generate() from
their plugin's Main class to do the generation.
| Modifier and Type | Field and Description |
|---|---|
protected Parameters |
parameters
Stores build parameters.
|
| Constructor and Description |
|---|
ProtocPluginCodeGenerator() |
| Modifier and Type | Method and Description |
|---|---|
void |
generate()
This is the interface into the
ProtocPluginCodeGenerator. |
protected java.util.Optional<java.lang.String> |
generateCode(AbstractDescriptor abstractDescriptor) |
protected java.util.Optional<java.lang.String> |
generateEnumCode(EnumDescriptor enumDescriptor)
Generate the Java code for a particular
EnumDescriptor. |
protected abstract java.lang.String |
generateImports()
Generate the Java imports required by the generated code in your plugin.
|
protected java.util.Optional<java.lang.String> |
generateMessageCode(MessageDescriptor messageDescriptor)
Generate the Java code for a particular
MessageDescriptor. |
protected abstract java.lang.String |
generatePluginJavaClass(java.lang.String protoJavaClass)
This method should return the name of the plugin's outer Java class for a particular file,
derived from the name of the outer Java class generated by the regular protobuf compiler.
|
protected java.util.Optional<java.lang.String> |
generateServiceCode(ServiceDescriptor serviceDescriptor)
Generate the Java code for a particular
ServiceDescriptor. |
protected abstract java.lang.String |
getPluginName()
This method should return the name of the plugin.
|
protected boolean |
skipFile(com.google.protobuf.DescriptorProtos.FileDescriptorProto fileDescriptorProto)
Whether or not to skip generating code for a particular file.
|
protected final Parameters parameters
@Nonnull protected abstract java.lang.String getPluginName()
@Nonnull
protected abstract java.lang.String generatePluginJavaClass(@Nonnull
java.lang.String protoJavaClass)
protoJavaClass - The Java class generated by the regular protobuf compiler. For example
if you have a TestDTO.proto file, this will be "TestDTO".@Nonnull protected abstract java.lang.String generateImports()
@Nonnull
protected java.util.Optional<java.lang.String> generateEnumCode(@Nonnull
EnumDescriptor enumDescriptor)
EnumDescriptor.enumDescriptor - The EnumDescriptor for an enum defined in the .proto file.Optional containing a string of Java code generated from the input descriptor.
An empty Optional if this particular plugin doesn't want to generate anything based
on enums.@Nonnull
protected java.util.Optional<java.lang.String> generateMessageCode(@Nonnull
MessageDescriptor messageDescriptor)
MessageDescriptor.messageDescriptor - The MessageDescriptor for a message defined in the .proto file.Optional containing a string of Java code generated from the input descriptor.
An empty Optional if this particular plugin doesn't want to generate anything based
on messages.@Nonnull
protected java.util.Optional<java.lang.String> generateServiceCode(@Nonnull
ServiceDescriptor serviceDescriptor)
ServiceDescriptor.serviceDescriptor - The ServiceDescriptor for a message defined in the .proto file.Optional containing a string of Java code generated from the input descriptor.
An empty Optional if this particular plugin doesn't want to generate anything based
on services.protected boolean skipFile(@Nonnull
com.google.protobuf.DescriptorProtos.FileDescriptorProto fileDescriptorProto)
fileDescriptorProto - The descriptor of the file.@Nonnull
protected final java.util.Optional<java.lang.String> generateCode(@Nonnull
AbstractDescriptor abstractDescriptor)
public final void generate()
throws java.io.IOException
ProtocPluginCodeGenerator.
Plugin implementations should call this method from their Main class to:
1) Read the PluginProtos.CodeGeneratorRequest from stdin.
2) Generate code and format a PluginProtos.CodeGeneratorResponse.
3) Write the response to stdout.java.io.IOException - If there is an issue with reading/writing from/to stdin/stdout.