Interface EmitterContext


public interface EmitterContext
What an emitter is given to write one contract's classes.
  • Method Summary

    Modifier and Type
    Method
    Description
    degraded(String className, String method, Finding finding)
    Records that a generated method cannot represent a construct, and returns the statement its body consists of instead: one that throws UnsupportedOperationException with the reason and, where there is one, the remedy.
    The contract.
    The core classes, whose names an emitter's companions follow.
    How the project has asked for the classes to be generated.
    void
    writeJava(String packageName, String simpleName, String source)
    Writes one Java source file, replacing any file already written for that class in this run.
    void
    writeResource(String path, String content)
    Writes one resource file, replacing any file already written at that path in this run -- a properties file a generated or hand-written class reads through getResourceAsStream, for instance.
  • Method Details

    • model

      ContractModel model()
      The contract.
      Returns:
      the model
    • settings

      Settings settings()
      How the project has asked for the classes to be generated.
      Returns:
      the settings
    • names

      ClassNames names()
      The core classes, whose names an emitter's companions follow.
      Returns:
      the class names
    • writeJava

      void writeJava(String packageName, String simpleName, String source)
      Writes one Java source file, replacing any file already written for that class in this run.
      Parameters:
      packageName - the package
      simpleName - the class's simple name
      source - the whole compilation unit
    • writeResource

      void writeResource(String path, String content)
      Writes one resource file, replacing any file already written at that path in this run -- a properties file a generated or hand-written class reads through getResourceAsStream, for instance.

      path is /-separated and relative to the resource root, and may nest in directories, such as "META-INF/emitter/service.properties". It may not be absolute, and may not use empty, . or .. segments.

      Parameters:
      path - the resource's path within the resource root
      content - the resource's content, written UTF-8
    • degraded

      String degraded(String className, String method, Finding finding)
      Records that a generated method cannot represent a construct, and returns the statement its body consists of instead: one that throws UnsupportedOperationException with the reason and, where there is one, the remedy. Every degraded method is reported at the end of generation.
      Parameters:
      className - the simple name of the class the method is in
      method - the method, as a reader would name it, such as body(String)
      finding - the construct it cannot represent
      Returns:
      a Java statement, without indentation