Class TemplateController
java.lang.Object
de.monticore.generating.templateengine.TemplateController
Provides methods for manipulating the content of templates, mainly for
calling and including of templates.
-
Field Summary
FieldsModifier and TypeFieldDescriptionAccording to FreeMarker, templates don't have a "signature" We can mimic such a signature through method calls: The signature(...) method defines a list of variables.static final StringVariable name for the current node (used in the templates)protected final GeneratorSetupGeneral config variables that hold for all template executionsprotected freemarker.template.SimpleHashstatic final StringVariable name for the GLEX object (used in the templates)static final StringVariable name for the current TemplateController (used in the templates)list that contains all the Template names that should be blocked from generating comments forprotected StringName of the current template (usually fully qualified) -
Constructor Summary
ConstructorsConstructorDescriptionTemplateController(GeneratorSetup setup, String templatename) TemplateController(GeneratorSetup setup, String templatename, List<String> templateBlackList) -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcompleteQualifiedName(String name) checks if the name seems to be already qualified: if not, adds the current package (of the template it operates on)voidvoidgetters and setters for the relevant attributesprotected ObjectgetValueFromData(String name) voidThis is an unusual method.Includes a template without an explicit ast.Include the template into the currently processed output.Execute the single template on each ASTNode of the list.Includes a template without an explicit ast.Execute each of the templates on the ASTNode.Execute each of the templates on each ASTNode of the list.includeArgs(String templateName, ASTNode node, List<Object> templateArguments) Include the template into the currently processed output.includeArgs(String templateName, String... templateArgument) Delegates toincludeArgs(String, List)includeArgs(String templateName, List<Object> templateArguments) Include the template into the currently processed output.voidprotected voidInit template aliases if not already done.instantiate(String className) Can be used to instantiate any Java-class with a default constructor (no args).instantiate(String className, List<Object> params) Can be used to instantiate any Java-class with constructor of a signature fitting to the params.booleanisTemplateNoteGenerated(freemarker.template.Template template) protected StringprocessTemplate(String templateName, ASTNode astNode, List<Object> passedArguments) Include a template with additional data: We only handle one template on one node.voidsetTemplateBlackList(List<String> templateBlackList) protected voidsetTemplatename(String templatename) protected voidsetValueToData(String name, Object value) voidDelegates tosignature(List).voidDefines the signature of a template.voidvoidvoidExecute the template and put the result into a file.voidvoidvoidwriteArgs(String templateName, String qualifiedFileName, String fileExtension, ASTNode ast, List<Object> templateArguments) Execute the template and put the result into a file.voidProcesses the templatetemplateNamewith theastand the giventemplateArgumentsand writes the content into thefilePath.
-
Field Details
-
AST
Variable name for the current node (used in the templates)- See Also:
-
TC
Variable name for the current TemplateController (used in the templates)- See Also:
-
GLEX
Variable name for the GLEX object (used in the templates)- See Also:
-
config
General config variables that hold for all template executions -
templateBlackList
list that contains all the Template names that should be blocked from generating comments for -
templatename
Name of the current template (usually fully qualified) -
arguments
According to FreeMarker, templates don't have a "signature" We can mimic such a signature through method calls: The signature(...) method defines a list of variables. And the include call allows a list of arguments that are bound to these variables, when the template is executed. -
data
protected freemarker.template.SimpleHash data
-
-
Constructor Details
-
TemplateController
-
TemplateController
public TemplateController(GeneratorSetup setup, String templatename, List<String> templateBlackList)
-
-
Method Details
-
getGeneratorSetup
getters and setters for the relevant attributes -
getTemplatename
-
setTemplatename
-
getTemplateBlackList
-
setTemplateBlackList
-
include
Execute each of the templates on each ASTNode of the list. Concatenate the results together in one big String and include that into the currently processed output. We iterate on the templates and ASTNodes. In case order is important: The iteration goes like this: for ( templates ) { for ( ASTNodes ) {...} } Inside the inner loop, it is checked whether Hookpoints are to be called. Template filename may be qualified (using "."). When it is not qualified, the filename is taken from the current package (same as the calling template).- Parameters:
templatenames- list of filenames, qualified or notastlist- where we execute the template on in an iteration- Returns:
- produced output
-
isTemplateNoteGenerated
public boolean isTemplateNoteGenerated(freemarker.template.Template template) -
signature
Defines the signature of a template. Note that, due to technical constraints, at first, the current template is included and the arguments are passed. Second, the signature is defined.- Parameters:
parameterNames- the list of the parameter names (=signature)
-
signature
Delegates tosignature(List). -
include
Includes a template without an explicit ast. (ast is current ast node)- Parameters:
templateName-- Returns:
-
include
Includes a template without an explicit ast. (ast is current ast node) Execute each of the templates on the ASTNode. Concatenate the results together in one big String and include that into the currently processed output. We iterate on the templates. Template filename may be qualified (using "."). When it is not qualified, the filename is taken from the current package (same as the calling template).- Parameters:
templateNames- list of filenames, qualified or not- Returns:
- produced output
-
include
Execute each of the templates on the ASTNode. Concatenate the results together in one big String and include that into the currently processed output. We iterate on the templates. Template filename may be qualified (using "."). When it is not qualified, the filename is taken from the current package (same as the calling template).- Parameters:
templateNames- list of filenames, qualified or notast- ast-node the template is operating on- Returns:
- produced output
-
include
Execute the single template on each ASTNode of the list. Concatenate the results together in one big String and include that into the currently processed output. We iterate on the ASTNodes. Template filename may be qualified (using "."). When it is not qualified, the filename is taken from the current package (same as the calling template).- Parameters:
templateName- filename, qualified or notastlist- where we execute the template on in an iteration- Returns:
- produced output
-
include
Include the template into the currently processed output. The template is executed on ASTNode ast. Remark: even though the name suggests to run several templates, this is the version that executes on a single template given as string. We only handle one template on one node. Template filename may be qualified (using "."). When it is not qualified, the filename is taken from the current package (same as the calling template).- Parameters:
templateName- name of the template to be executed, qualified or notast- ast-node the template is operating on- Returns:
- output for the file (may be part of a file only)
-
includeArgs
Include the template into the currently processed output. Remark: even though the name suggests to run several templates, this is the version that executes on a single template given as string. We only handle one template on one node. Template filename may be qualified (using "."). When it is not qualified, the filename is taken from the current package (same as the calling template).- Parameters:
templateName- name of the template to be executed, qualified or nottemplateArguments- additional data that is passed to the called template- Returns:
- output for the file (may be part of a file only)
-
includeArgs
Include the template into the currently processed output. Remark: even though the name suggests to run several templates, this is the version that executes on a single template given as string. We only handle one template on one node. Template filename may be qualified (using "."). When it is not qualified, the filename is taken from the current package (same as the calling template).- Parameters:
templateName- name of the template to be executed, qualified or nottemplateArguments- additional data that is passed to the called template- Returns:
- output for the file (may be part of a file only)
-
includeArgs
Delegates toincludeArgs(String, List) -
include
This is an unusual method. It does nothing and should not be used. It will be called from freemarker automatically, when one of the arguments (either the filename or the ast) is null. In this case an error is issued.- Parameters:
empty1-empty2-
-
write
Execute the template and put the result into a file. The template is executed on ASTNode ast. File qualifiedFileName + default file extension is opened, written and closed again!- Parameters:
templateName- full qualified filenameast- where we execute the template on
-
write
-
write
-
writeArgs
public void writeArgs(String templateName, String qualifiedFileName, String fileExtension, ASTNode ast, List<Object> templateArguments) Execute the template and put the result into a file. The template is executed on ASTNode ast. And the file qualifiedFileName + fileExtension is opened, written and closed again! If fileExtension == null, then use "". fileExtension may start with ".", otherwise one is added. So ".java" and "java" have the same effect. Template filename may be qualified (using "."). When it is not qualified, the filename is taken from the current package (same as the calling template).- Parameters:
templateName- full qualified filenameast- where we execute the template on
-
writeArgs
public void writeArgs(String templateName, Path filePath, ASTNode ast, List<Object> templateArguments) Processes the templatetemplateNamewith theastand the giventemplateArgumentsand writes the content into thefilePath. Note: Unless not absolute, thefilePathis relative to the configured target directory (i.e.,- Parameters:
templateName- the template to be processesfilePath- the file path in which the content is to be writtenast- the asttemplateArguments- additional template arguments (if needed).
-
processTemplate
protected String processTemplate(String templateName, ASTNode astNode, List<Object> passedArguments) Include a template with additional data: We only handle one template on one node. This method allows to parameterize templates. Template filename may be qualified (using "."). When it is not qualified, the filename is taken from the current package. The resulting output may be stored or included in another generation process.- Parameters:
templateName- name of the template to be executed, qualified or notastNode- ast-node the template is operating onpassedArguments- additional data that is passed to the included template- Returns:
- output for the file (may be part of a file only)
-
initAliases
protected void initAliases()Init template aliases if not already done. This happens once (for all main templates) -
completeQualifiedName
checks if the name seems to be already qualified: if not, adds the current package (of the template it operates on) -
getValueFromData
-
setValueToData
-
instantiate
Can be used to instantiate any Java-class with a default constructor (no args). The passed className is either in the same package as the calling template, or it needs to be qualified (dot-separated).- Parameters:
className- name of the class to be instantiated- Returns:
- an object of the given className
-
instantiate
Can be used to instantiate any Java-class with constructor of a signature fitting to the params. The passed className is either in the same package as the calling template, or it needs to be qualified (dot-separated).- Parameters:
className- name of the class to be instantiatedparams- parameters provided for the constructor-call- Returns:
- an object of the given className
-
trace
- See Also:
-
debug
- See Also:
-
info
- See Also:
-
warn
- See Also:
-
error
- See Also:
-