Annotation Interface JStacheInterfaces


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:

  1. type annotated with JStache and this annotation.
  2. enclosing class (of type annotated with JStache) with this annotation with inner to outer order.
  3. package annotated with this annotation.
  4. module annotated with this annotation.
If multiple annotations are found the first one is picked and there is no combining of settings. See 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

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Class<?>[]
    Will check that all models in the annotated class/package/module annotated with JStache 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.
    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

      Will 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:

      1. templateFormatter() (see io.jstach.jstachio.TemplateInfo)
      2. templateEscaper() (see io.jstach.jstachio.TemplateInfo)
      3. 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

      Will 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

      Will check that all models in the annotated class/package/module annotated with JStache implement the array of interfaces. If a model does not a compilation error will happen.
      Returns:
      interfaces that the models should implement
      Default:
      {}