Interface CommonCodeGenerator


public interface CommonCodeGenerator
Services to be called by the custom code generator for the generic cases of Java code generation.
  • Field Details

    • CONST_CACHE_FIELDS_PREFIX

      static final String CONST_CACHE_FIELDS_PREFIX
      The prefix used to buld field names for the numbered recognized constants.
      See Also:
    • NAME_VAR_FORMAT_EMPTY

      static final String NAME_VAR_FORMAT_EMPTY
      Name of the field which contains an empty format, in the generated format generator class. (Field of that generated class must be initialized by the caller, to contain an empty format.)
      See Also:
    • FORMAT_VAR_FORMAT_EMPTY

      static final Format FORMAT_VAR_FORMAT_EMPTY
      Will be resolved relative to the containing generated class. (Field of the generated class must be initialized by the caller, to contain an empty format.)
    • NAME_VAR_MODE

      static final String NAME_VAR_MODE
      Name of the variable holding the "mode" value for switch statements.
      See Also:
    • FORMAT_VAR_MODE

      static final Format FORMAT_VAR_MODE
      Access to the variable holding the "mode" value for switch statements.
    • VALUE_DEFAULTINDENT

      static final int VALUE_DEFAULTINDENT
      The value to which the default indentation will be initialized. (The default indentation can be changed arbitrarily for format generation.)
      See Also:
    • NAME_VAR_DEFAULTINDENT

      static final String NAME_VAR_DEFAULTINDENT
      Access to the variable holding the default value for indentations.
      See Also:
    • FORMAT_VAR_DEFAULTINDENT

      static final Format FORMAT_VAR_DEFAULTINDENT
      Access to the variable holding the default value for indentations.
    • NAME_CLASS_TAKEALTERNATIVE

      static final String NAME_CLASS_TAKEALTERNATIVE
      The name of the "take-alternative" exception class, as defined in the format generating class.
      See Also:
    • NAME_INSTANCE_TAKEALTERNATIVE

      static final String NAME_INSTANCE_TAKEALTERNATIVE
      The name of one constant intstance of the "take-alternative" exception class, as defined in the format generating class.
      See Also:
    • NAME_METHOD_TAKEALTERNATIVE

      static final String NAME_METHOD_TAKEALTERNATIVE
      The name of the method in the format generating class which throws a "take-alternative" Exception, as defined also in that class.
      See Also:
    • FORMAT_METHOD_TAKEALTERNATIVE

      static final Format FORMAT_METHOD_TAKEALTERNATIVE
      The name of the method in the format generating class which throws a "take-alternative" Exception, as defined also in that class.
    • NAME_METHOD_TRYCATCH

      static final String NAME_METHOD_TRYCATCH
      The name of the method in the format generating class which tries one format and executes a second format in case of a catch.
      See Also:
    • REF_FORMAT_Format

      static final Format REF_FORMAT_Format
      A format which tells metajava to access the Format class.
    • REF_FORMAT_Formats

      static final Format REF_FORMAT_Formats
      A format which tells metajava to access the Formats class.
  • Method Details

    • newInstance

      Yields a new instance of an implementation.

      (This allows technically that the implementing class is not known by a client classes = a custom compiler.)

      Parameters:
      msg - the target of all generated errors and warnings.
      Returns:
      an instance of an implementation of this interface.
    • reifyConstantCache

      default void reifyConstantCache(GeneratedClass cls, int modifier)
      Adds the collected constant expressions as field definitions to the formatter class under construction.
      Parameters:
      cls - to which the field definitions shall be added
      modifier - for all created fields
    • process

      Format process(Model.Expr expr)
      Returns the format which realizes the code to generate the format, and additionally updates the constant caches. Both must eventually be realized by the generated class.
      Parameters:
      expr - the model expressions which shall be translated into Java code
      Returns:
      the Java code which will generate the specified format
    • javaExpr

      Format javaExpr(String codeText)
      Translate the source text of a Java statement into a Format. In particular, the source text can contain variables to be resolved by Format methods.
      Parameters:
      codeText - the source of a Java statement, possibly with embedded variables.
      Returns:
      the Format representation of the successfully parsed Java source
      Throws:
      IllegalArgumentException - in case of Java syntax errors
    • javaStatement

      Format javaStatement(String codeText)
      Translate the source text of a Java statement into a Format. In particular, the source text can contain variables to be resolved by Format methods.
      Parameters:
      codeText - the source of a Java statement, possibly with embedded variables.
      Returns:
      the Format representation of the successfully parsed Java source
      Throws:
      IllegalArgumentException - in case of Java syntax errors
    • setCustomCodeGenerator

      void setCustomCodeGenerator(CustomCodeGenerator customCodeGenerator)
      Make the custom code generator known to the common code. This is neessary to embed the code generation for the specific model elements into the generated common code.
      Parameters:
      customCodeGenerator - the implementation used for the specific custom epxressions.
    • constIndex2constFormat

      SortedMap<Integer,Format> constIndex2constFormat()
      Maps the number of a recognized constant format to that format.
      Returns:
      the Map with the numbering of recognized constant formats.
    • prepareRuntimeEnvironment

      void prepareRuntimeEnvironment(GeneratedClass cls)
      Add all field and method definitions which are assumed to exist by the common code generator.

      import statements are not added, because this can be critical in particular contexts.

      Parameters:
      cls - the class to which the definitions are added. The fields and methods of this class must be accessible by the generated code.