Class Generator

java.lang.Object
com.salesforce.jprotoc.Generator
Direct Known Subclasses:
InterfaceProtocPlugin

public abstract class Generator extends Object
Generator is the base class for all protoc generators managed by ProtocPlugin.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    applyTemplate(String resourcePath, Object generatorContext)
    Executes a mustache template against a generatorContext object to generate an output string.
    Stream<com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File>
    generate(com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest request)
    Deprecated.
    use generateFiles(PluginProtos.CodeGeneratorRequest) and return a List instead of a Stream.
    List<com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File>
    generateFiles(com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest request)
    Processes a generator request into a set of files to output.
    protected com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File
    makeFile(String fileName, byte[] fileContent)
    Creates a protobuf file message from a given name and content.
    protected com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File
    makeFile(String fileName, String fileContent)
    Creates a protobuf file message from a given name and content.
    protected List<com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.Feature>
    Signals to protoc which additional generator features this Generator supports.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Generator

      public Generator()
  • Method Details

    • generate

      @Deprecated public Stream<com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File> generate(com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest request) throws GeneratorException
      Deprecated.
      use generateFiles(PluginProtos.CodeGeneratorRequest) and return a List instead of a Stream.
      Processes a generator request into a set of files to output.
      Parameters:
      request - The raw generator request from protoc.
      Returns:
      The completed files to write out.
      Throws:
      GeneratorException
    • generateFiles

      public List<com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File> generateFiles(com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest request) throws GeneratorException
      Processes a generator request into a set of files to output.
      Parameters:
      request - The raw generator request from protoc.
      Returns:
      The completed files to write out.
      Throws:
      GeneratorException
    • supportedFeatures

      protected List<com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.Feature> supportedFeatures()
      Signals to protoc which additional generator features this Generator supports. By default, this method returns FEATURE_NONE. You must override this method and supply a value, like FEATURE_PROTO3_OPTIONAL.
      Returns:
      A list of enumerated features.
    • applyTemplate

      protected String applyTemplate(@Nonnull String resourcePath, @Nonnull Object generatorContext)
      Executes a mustache template against a generatorContext object to generate an output string.
      Parameters:
      resourcePath - Embedded resource template to use.
      generatorContext - Context object to bind the template to.
      Returns:
      The string that results.
    • makeFile

      protected com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File makeFile(String fileName, String fileContent)
      Creates a protobuf file message from a given name and content.
      Parameters:
      fileName - The name of the file to generate.
      fileContent - The content of the generated file.
      Returns:
      The protobuf file.
    • makeFile

      protected com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse.File makeFile(String fileName, byte[] fileContent)
      Creates a protobuf file message from a given name and content.
      Parameters:
      fileName - The name of the file to generate.
      fileContent - The content of the generated file.
      Returns:
      The protobuf file.