This annotation is useful to force models and templates implement interfaces or have
annotations particularly where you want all models to implement a lambda mixin
interface. It also maybe useful to make generateed code have annotations for DI
frameworks (Spring, Dagger, CDI, etc) to find generated templates as components.
Order of config lookup and precedence is as follows:
- type annotated with JStache and this annotation.
- enclosing class (of type annotated with JStache) with this annotation with inner to outer order.
- package annotated with this annotation.
- module annotated with this annotation.
JStacheConfig
for general config resolution.
Example
@JStacheInterfaces(templateAnnotations=Component.class)
module com.myapp {
require transitive io.jstach.jstachio;
}
or for package level
@JStacheInterfaces(templateImplements=MyMixin.class)
package com.myapp.templates;
Now all generated templates (aka renderers) that are in the com.myapp
module and com.myapp.templates
will be generated like:
@Component
public class MyTemplate implements MyMixin /*, possibly more needed for jstachio */ {
// implementation ommitted
}
- Author:
- agentgt
- See Also:
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionClass<?>[]
Will check that all models in the annotated class/package/module annotated withJStache
implement the array of interfaces.Class<?>[]
Will make all generated templates that are in the annotated class/package/module be annotated with the array of annotations.Class<?>
Will make all generated templates that are in the annotated class/package/module extened a class.Class<?>[]
Will make all generated templates that are in the annotated class/package/module implement the array of interfaces.
-
Element Details
-
templateImplements
Class<?>[] templateImplementsWill make all generated templates that are in the annotated class/package/module implement the array of interfaces. If the interface has a single generic type parameter (e.g.SomeInterface<T>
) then the parameter will be assumed to be the model type (the class annotated with JStache) and thus will be parameterized with the model type (e.g.SomeModelRenderer implements SomeInterface<SomeModel>
).The interfaces should have a default implementation for all of its methods otherwise possible compilation errors might happen.
- Returns:
- interfaces that generated template will implement
- Default:
- {}
-
templateExtends
Will make all generated templates that are in the annotated class/package/module extened a class. If the class has a single generic type parameter (e.g.SomeClass<T>
) then the parameter will be assumed to be the model type (the class annotated with JStache) and thus will be parameterized with the model type (e.g.SomeModelRenderer extends SomeClass<SomeModel>
).The class needs a no arg default constructor but may provide other constructors that will simply be replicated (including annotations!) on the genererated template.
Furthermore some methods will not be generated if the
templateExtends
class has a concrete implementation (not abstract).Below are the methods that will not be generated if present on the parent class:
templateFormatter()
(see io.jstach.jstachio.TemplateInfo)templateEscaper()
(see io.jstach.jstachio.TemplateInfo)execute(T, Appendable)
(see io.jstach.jstachio.Template , the templateExtends class will need to be parameterized for this to work)
- Returns:
- interfaces that generated template will implement
- Default:
- java.lang.Object.class
-
templateAnnotations
Class<?>[] templateAnnotationsWill make all generated templates that are in the annotated class/package/module be annotated with the array of annotations. The order is preserved in the generated code.- Returns:
- annotations to be added to generate templates
- Default:
- {}
-
modelImplements
Class<?>[] modelImplementsWill check that all models in the annotated class/package/module annotated withJStache
implement the array of interfaces. If a model does not a compilation error will happen.- Returns:
- interfaces that the models should implement
- Default:
- {}
-