Package eu.bandm.tools.formattext
Interface CommonCodeGenerator
public interface CommonCodeGenerator
Services to be called by the custom code generator for the generic
cases of Java code generation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe prefix used to buld field names for the numbered recognized constants.static final FormatThe name of the method in the format generating class which throws a "take-alternative" Exception, as defined also in that class.static final FormatAccess to the variable holding the default value for indentations.static final FormatWill be resolved relative to the containing generated class.static final FormatAccess to the variable holding the "mode" value for switch statements.static final StringThe name of the "take-alternative" exception class, as defined in the format generating class.static final StringThe name of one constant intstance of the "take-alternative" exception class, as defined in the format generating class.static final StringThe name of the method in the format generating class which throws a "take-alternative" Exception, as defined also in that class.static final StringThe name of the method in the format generating class which tries one format and executes a second format in case of a catch.static final StringAccess to the variable holding the default value for indentations.static final StringName of the field which contains an empty format, in the generated format generator class.static final StringName of the variable holding the "mode" value for switch statements.static final FormatA format which tells metajava to access the Format class.static final FormatA format which tells metajava to access the Formats class.static final intThe value to which the default indentation will be initialized. -
Method Summary
Modifier and TypeMethodDescriptionMaps the number of a recognized constant format to that format.Translate the source text of a Java statement into a Format.javaStatement(String codeText) Translate the source text of a Java statement into a Format.static CommonCodeGeneratorYields a new instance of an implementation.voidAdd all field and method definitions which are assumed to exist by the common code generator.process(Model.Expr expr) Returns the format which realizes the code to generate the format, and additionally updates the constant caches.default voidreifyConstantCache(GeneratedClass cls, int modifier) Adds the collected constant expressions as field definitions to the formatter class under construction.voidsetCustomCodeGenerator(CustomCodeGenerator customCodeGenerator) Make the custom code generator known to the common code.
-
Field Details
-
CONST_CACHE_FIELDS_PREFIX
The prefix used to buld field names for the numbered recognized constants.- See Also:
-
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
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
Name of the variable holding the "mode" value for switch statements.- See Also:
-
FORMAT_VAR_MODE
Access to the variable holding the "mode" value for switch statements. -
VALUE_DEFAULTINDENT
static final int VALUE_DEFAULTINDENTThe value to which the default indentation will be initialized. (The default indentation can be changed arbitrarily for format generation.)- See Also:
-
NAME_VAR_DEFAULTINDENT
Access to the variable holding the default value for indentations.- See Also:
-
FORMAT_VAR_DEFAULTINDENT
Access to the variable holding the default value for indentations. -
NAME_CLASS_TAKEALTERNATIVE
The name of the "take-alternative" exception class, as defined in the format generating class.- See Also:
-
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
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
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
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
A format which tells metajava to access the Format class. -
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
Adds the collected constant expressions as field definitions to the formatter class under construction.- Parameters:
cls- to which the field definitions shall be addedmodifier- for all created fields
-
process
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
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
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
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
Maps the number of a recognized constant format to that format.- Returns:
- the Map with the numbering of recognized constant formats.
-
prepareRuntimeEnvironment
Add all field and method definitions which are assumed to exist by the common code generator.importstatements 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.
-