001package io.jstach.jstache;
002
003import java.lang.annotation.Documented;
004import java.lang.annotation.ElementType;
005import java.lang.annotation.Retention;
006import java.lang.annotation.RetentionPolicy;
007import java.lang.annotation.Target;
008import java.util.Map;
009import java.util.Optional;
010
011/**
012 * Generates a JStachio Renderer from a template and a model (the annotated class).
013 * <p>
014 * Classes annotated are typically called "models" as they will be the root context for
015 * the template.
016 *
017 * <h2 class="toc-title">Contents</h2> <div class="js-toc"></div>
018 * <div class="js-toc-content">
019 * <h2 id="_example">Example Usage</h2>
020 *
021 * <pre class="code">
022 * <code class="language-java">
023 * &#64;JStache(template = &quot;&quot;&quot;
024 *     {{#people}}
025 *     {{message}} {{name}}! You are {{#ageInfo}}{{age}}{{/ageInfo}} years old!
026 *     {{#-last}}
027 *     That is all for now!
028 *     {{/-last}}
029 *     {{/people}}
030 *     &quot;&quot;&quot;)
031 * public record HelloWorld(String message, List&lt;Person&gt; people) implements AgeLambdaSupport {}
032 *
033 * public record Person(String name, LocalDate birthday) {}
034 *
035 * public record AgeInfo(long age, String date) {}
036 *
037 * public interface AgeLambdaSupport {
038 *   &#64;JStacheLambda
039 *   default AgeInfo ageInfo(
040 *       Person person) {
041 *     long age = ChronoUnit.YEARS.between(person.birthday(), LocalDate.now());
042 *     String date = person.birthday().format(DateTimeFormatter.ISO_DATE);
043 *     return new AgeInfo(age, date);
044 *   }
045 * }
046 * </code> </pre>
047 *
048 * <h2 id="_model_and_templates">Models and Templates</h2>
049 *
050 * Because JStachio checks types its best to think of the model and template as married.
051 * With the exception of partials JStachio cannot have a template without a model and vice
052 * versa. The way to create Renderer (what we call the model and template combined) is to
053 * annotate your model with {@link io.jstach.jstache.JStache}.
054 *
055 * <h3 id="_models">Models</h3> <strong>&#64;{@link io.jstach.jstache.JStache}</strong>
056 * <p>
057 * A JStachio model can be any class type including Records and Enums so long as you can
058 * you annotate the type with {@link io.jstach.jstache.JStache}.
059 * <p>
060 * When the compiler runs the annotation processor will create readable java classes that
061 * are suffixed with "Renderer" which will have methods to write the model to an
062 * {@link java.lang.Appendable}. The generated instance methods are named
063 * <code>execute</code> and the corresponding static methods are named
064 * <code>render</code>.
065 * <p>
066 * <em>TIP: If you like to see the generated classes from the annotation processor they
067 * usually get put in <code>target/generated-sources/annotations</code> for Maven
068 * projects.</em>
069 *
070 * <h4 id="_decorating_models">Adding interfaces to models and renderers</h4>
071 * <strong>&#64;{@link io.jstach.jstache.JStacheInterfaces}</strong>
072 * <p>
073 * Java has a huge advantage over JSON and Javascript. <em>You can use interfaces to add
074 * additional variables as well as lambda methods
075 * ({@link io.jstach.jstache.JStacheLambda})!</em> To enforce that certain interfaces are
076 * added to models (the ones annotated) and renderers (the generated classes) you can use
077 * {@link io.jstach.jstache.JStacheInterfaces} on packages or the classes themselves.
078 * <p>
079 * You can also make generated classes have {@link ElementType#TYPE} annotations (see
080 * {@link JStacheInterfaces#templateAnnotations()}) and extend a class
081 * {@link JStacheInterfaces#templateExtends()}) as well which maybe useful for integration
082 * with other frameworks particularly DI frameworks.
083 *
084 * <h3 id="_templates">Templates</h3>
085 *
086 * The format of the templates should by default be Mustache. The syntax is informally
087 * explained by the
088 * <a href="https://jgonggrijp.gitlab.io/wontache/mustache.5.html">mustache manual</a> and
089 * formally explained by the <a href="https://github.com/mustache/spec">spec</a>. There
090 * are some subtle differences in JStachio version of Mustache due to the static nature
091 * that are discussed in <a href="#_context_lookup">context lookup</a>. <strong>Template
092 * finding is as follows:</strong>
093 * <ol>
094 * <li><code>path</code> which is a classpath with slashes following the same format as
095 * the ClassLoader resources. The path maybe augmented with {@link JStachePath}.
096 * <li><code>template</code> which if not empty is used as the template contents
097 * <li>if the above is not set then the name of the class suffixed with ".mustache" is
098 * used as the resource.
099 * </ol>
100 *
101 * <h4 id="_inline_templates">Inline Templates</h4>
102 * <strong>{@link io.jstach.jstache.JStache#template()}</strong>
103 * <p>
104 * Inline templates are pretty straight forward. Just set
105 * {@link io.jstach.jstache.JStache#template()} to a literal string. If you go this route
106 * it is <em>highly recommend you use the new triple quote string literal for inline
107 * templates</em>
108 *
109 * <h4 id="_resource_templates">Resource Templates</h4>
110 * <strong>{@link io.jstach.jstache.JStache#path()} and
111 * &#64;{@link io.jstach.jstache.JStachePath} </strong>
112 * <p>
113 * Resource templates are files that are in the classpath and are more complicated because
114 * of lookup resolution.
115 * <p>
116 * When the annotation processor runs these files usually are in:
117 * <code>javax.tools.StandardLocation#CLASS_OUTPUT</code> and in a Maven or Gradle project
118 * they normally would reside in <code>src/main/resources</code> or
119 * <code>src/test/resources</code> which get copied on build to
120 * <code>target/classes</code> or similar. <em>N.B. becareful not to have resource
121 * filtering turned on for mustache templates.</em>
122 * <p>
123 * Ideally JStachio would use <code>javax.tools.StandardLocation#SOURCE_PATH</code> to
124 * find resource templates but that is currently <a href=
125 * "https://stackoverflow.com/questions/22494596/eclipse-annotation-processor-get-project-path">
126 * problematic with incremental compilers such as Eclipse</a>.
127 * <p>
128 * Another issue with incremental compiling is that template files are not always copied
129 * after being edited to <code>target/classes</code> and thus are not found by the
130 * annotation processor. To deal with this issue JStachio during compilation fallsback to
131 * direct filesystem access and assumes that your templates are located:
132 * <code>CWD/src/main/resources</code>. That location is configurable via the annotation
133 * processor option {@link #RESOURCES_PATH_OPTION}
134 * (<strong>{@value #RESOURCES_PATH_OPTION}</strong>).
135 *
136 * <p>
137 * Normally you need to specify the full path in {@link #path()} which is a resource path
138 * (and not a file path) as specified by {@link ClassLoader#getResource(String)} however
139 * you can make path expansion happen with {@link io.jstach.jstache.JStachePath} which
140 * allows you to prefix and suffix the path.
141 *
142 * <h4 id="_partials">Partials</h4>
143 * <strong><code>{{&gt; partial }} and {{&lt; parent }}{{/parent}} </code></strong>
144 * <p>
145 * JStachio supports Mustache partials (and parents) and by default works just like
146 * template resources such that {@link io.jstach.jstache.JStachePath} is used for
147 * resolution if specified.
148 * <p>
149 * You may also remap partial names via {@link io.jstach.jstache.JStachePartial} to a
150 * different location as well as to an inline template (string literal).
151 *
152 * <h4 id="_fragments">Fragments</h4>
153 *
154 * JStachio allows referencing a <a href="https://htmx.org/essays/template-fragments/">
155 * subset of a template called "fragments"</a>. The subset of a template can be any type
156 * of section block and the <em>first one found from top to bottom reading with the
157 * matching name</em> is picked. The subset of a resource template is referenced with the
158 * URI fragment notation.
159 *
160 * <p>
161 * For example let us say we have a template like <code>/contacts/details.mustache</code>:
162 * <pre><code class="language-hbs">
163 * &lt;html&gt;
164 *     &lt;body&gt;
165 *         &lt;div hx-target="this"&gt;
166 *           {{#archive-ui}}
167 *             {{#contact.archived}}
168 *             &lt;button hx-patch="/contacts/${contact.id}/unarchive"&gt;Unarchive&lt;/button&gt;
169 *             {{/contact.archived}}
170 *             {{^contact.archived}}
171 *             &lt;button hx-delete="/contacts/${contact.id}"&gt;Archive&lt;/button&gt;
172 *             {{/contact.archived}}
173 *           {{/archive-ui}}
174 *         &lt;/div&gt;
175 *         &lt;h3&gt;Contact&lt;/h3&gt;
176 *         &lt;p&gt;${contact.email}&lt;/p&gt;
177 *     &lt;/body&gt;
178 * &lt;/html&gt;
179 * </code> </pre>
180 *
181 * <pre><code class="language-java">
182 * &#64;JStache("/contacts/details.mustache#archive-ui")
183 * public record ContactDetails(Contact contact){}
184 * </code> </pre>
185 *
186 * The effective template for <code>ContactDetails</code> would be:
187 *
188 * <pre><code class="language-hbs">
189 *   {{#contact.archived}}
190 *   &lt;button hx-patch="/contacts/${contact.id}/unarchive"&gt;Unarchive&lt;/button&gt;
191 *   {{/contact.archived}}
192 *   {{^contact.archived}}
193 *   &lt;button hx-delete="/contacts/${contact.id}"&gt;Archive&lt;/button&gt;
194 *   {{/contact.archived}}
195 * </code> </pre>
196 *
197 * <strong> If the fragment start tag is "standalone" and all the content inside the
198 * fragment start tag starts with the same whitespace (or more) as the fragment start tag
199 * starting whitespace will be stripped from each line of the content. </strong> This is
200 * to allow a partial references to dictate the indentation based on spec whitespace
201 * handling.
202 * <p>
203 * Fragment section blocks can be of these type:
204 * <ul>
205 * <li><code>{{#fragment}}</code></li>
206 * <li><code>{{$fragment}}</code></li>
207 * <li><code>{{&lt;fragment}}</code></li>
208 * <li><code>{{$fragment}}</code></li>
209 * </ul>
210 *
211 * The semantics of the section block are ignored as well as the rest of the template.
212 *
213 * <h4 id="_optional_spec">Optional Spec Support</h4> JStachio implements some optional
214 * parts of the specification. Below shows what is and is not supported.
215 * <table border="1">
216 * <caption><strong>Optional Spec Features Table</strong></caption>
217 * <tr>
218 * <th>Name</th>
219 * <th>Supported</th>
220 * <th>Manual Description</th>
221 * </tr>
222 * <tr>
223 * <td>Lambda variables (arity 0)</td>
224 * <td style="color:red;">NO</td>
225 * <td>An optional part of the specification states that if the final key in the name is a
226 * lambda that returns a string, then that string should be rendered as a Mustache
227 * template before interpolation. It will be rendered using the default delimiters (see
228 * Set Delimiter below) against the current context.</td>
229 * </tr>
230 * <tr>
231 * <td>Lambda sections (arity 1)</td>
232 * <td style="color:blue;">YES</td>
233 * <td>An optional part of the specification states that if the final key in the name is a
234 * lambda that returns a string, then that string replaces the content of the section. It
235 * will be rendered using the same delimiters (see Set Delimiter below) as the original
236 * section content. In this way you can implement filters or caching.</td>
237 * </tr>
238 * <tr>
239 * <td>Delimiters</td>
240 * <td style="color:blue;">YES</td>
241 * <td>Set Delimiter tags are used to change the tag delimiters for all content following
242 * the tag in the current compilation unit. The tag's content MUST be any two
243 * non-whitespace sequences (separated by whitespace) EXCEPT an equals sign ('=') followed
244 * by the current closing delimiter. Set Delimiter tags SHOULD be treated as standalone
245 * when appropriate. <em>(this feature is non-optional in current mustache but some
246 * mustaches implemenations treat it as optional)</em></td>
247 * </tr>
248 * <tr>
249 * <td>Dynamic Names</td>
250 * <td style="color:red;">NO</td>
251 * <td>Partials can be loaded dynamically at runtime using Dynamic Names; an optional part
252 * of the Mustache specification which allows to dynamically determine a tag's content at
253 * runtime.</td>
254 * </tr>
255 * <tr>
256 * <td>Blocks</td>
257 * <td style="color:blue;">YES</td>
258 * <td>A block begins with a dollar and ends with a slash. That is, {{$title}} begins a
259 * "title" block and {{/title}} ends it.</td>
260 * </tr>
261 * <tr>
262 * <td>Parents</td>
263 * <td style="color:blue;">YES</td>
264 * <td>A parent begins with a less than sign and ends with a slash. That is,
265 * {{&lt;article}} begins an "article" parent and {{/article}} ends it.</td>
266 * </tr>
267 * </table>
268 *
269 * <h3 id="_context_lookup">Context Lookup</h3>
270 *
271 * JStachio unlike almost all other Mustache implementations does its context lookup
272 * statically during compile time. Consequently JStachio pedantically is early bound where
273 * as Mustache is traditionally late bound. Most of the time this difference will not
274 * manifest itself so long as you avoid using {@link Map} in your models.
275 * <p>
276 * The other notable difference is JStachio does not like missing variables (a compiler
277 * error will happen) where as many Mustache implementations sometimes allow this and will
278 * just not output anything.
279 *
280 * <em> n.b. This doc and various other docs often appears to use the term "variable" and
281 * "binding" interchangeable. "variable" however is generally a subset of "binding" and is
282 * the leaf nodes of the model tree that are to be outputted like String
283 * interpolation.</em> In mustache spec parlance it is the last key (all the way to the
284 * right) of a dotted name. Also in some cases this doc calls dotted names "path".
285 *
286 *
287 * <h4 id="_context_java_types">Interpretation of Java-types and values</h4> When some
288 * value is null nothing is rendered if it is used as a section. If some value is null and
289 * it is used as a variable a null pointer exception will be thrown by default. This is
290 * configurable via {@link JStacheFormatterTypes} and custom {@link JStacheFormatter}.
291 * <p>
292 * Boxed and unboxed <code>boolean</code> can be used for mustache-sections. Section is
293 * only rendered if value is true.
294 * <p>
295 * {@link Optional} empty is treated like an empty list or a boolean false. Optional
296 * values are always assumed to be non null.
297 * <p>
298 * {@code Map<String,?>} follow different nesting rules than other types. If you are in a
299 * {@link Map} nested section the rest of the context is checked before the
300 * <code>Map</code>. Once that is done the Map is then checked using
301 * {@link Map#get(Object)}' where the key is the <em>last part of the dotted name</em>.
302 * <p>
303 * Data-binding contexts are nested. Names are looked up in innermost context first. If
304 * name is not found in current context, parent context is inspected. This process
305 * continues up to root context.
306 *
307 * In each rendering context name lookup is performed as follows:
308 *
309 * <ol>
310 * <li>Method with requested name is looked up. Method should have no arguments and should
311 * throw no checked exceptions. If there is such method it is used to fetch actual data to
312 * render. Compile-time error is raised if there is method with given name, but it is not
313 * accessible, has parameters or throws checked exceptions.</li>
314 * <li>Method with requested name and annotated correctly with {@link JStacheLambda} and
315 * the lookup is for a section than the method lambda method will be used.</li>
316 * <li>Method with getter-name for requested name is looked up. (For example, if 'age' is
317 * requested, 'getAge' method is looked up.) Method should have no arguments and should
318 * throw no checked exceptions. If there is such method it is used to fetch actual data to
319 * render. Compile-time error is raised if there is method with such name, but it is not
320 * accessible, has parameters or throws checked exceptions</li>
321 *
322 * <li>Field with requested name is looked up. Compile-time error is raised if there is
323 * field with such name but it's not accessible.</li>
324 * </ol>
325 *
326 * <h4 id="_enums">Enum Matching Extension</h4> Basically enums have boolean keys that are
327 * the enums name ({@code Enum.name()}) that can be used as conditional sections. Assume
328 * {@code light} is an enum like:
329 *
330 * <pre>
331 * <code class="language-java">
332 * public enum Light {
333 *   RED,
334 *   GREEN,
335 *   YELLOW
336 * }
337 * </code> </pre>
338 *
339 * You can conditinally select on the enum like a pattern match:
340 *
341 * <pre>
342 * <code class="language-hbs">
343 * {{#light.RED}}
344 * STOP
345 * {{/light.RED}}
346 * {{#light.GREEN}}
347 * GO
348 * {{/light.GREEN}}
349 * {{#light.YELLOW}}
350 * Proceeed with caution
351 * {{/light.YELLOW}}
352 * </code> </pre>
353 *
354 * <h4 id="_index_support">Index Extension</h4>
355 *
356 * JStachio is compatible with both handlebars.js (handlebars.java as well) and JMustache
357 * index keys for iterable sections.
358 * <ol>
359 * <li><code>-first</code> and <code>&#64;first</code> is boolean that is true when you
360 * are on the first item
361 * <li><code>-last</code> and <code>&#64;last</code> is a boolean that is true when you
362 * are on the last item in the iterable
363 * <li><code>-index</code> is a one based index. The first item would be {@code 1} and not
364 * {@code 0}
365 * <li><code>&#64;index</code> is zero based index (handlebars). The first item would be
366 * {@code 0}.
367 * </ol>
368 *
369 * <h3 id="_lambdas">Lambda Support</h3>
370 *
371 * <strong>&#64;{@link JStacheLambda}</strong>
372 * <p>
373 * JStachio supports lambda section calls in a similar manner to
374 * <a href="https://github.com/samskivert/jmustache">JMustache</a>. Just tag your methods
375 * with {@link JStacheLambda} and the returned models will be used to render the contents
376 * of the lambda section. The top of the context stack can be passed to the lambda.
377 *
378 *
379 * <h2 id="_code_generation">Code Generation</h2>
380 *
381 * <strong>&#64;{@link io.jstach.jstache.JStacheConfig#type()}</strong>
382 * <p>
383 * JStachio by default reads mustache syntax and generates code that needs the jstachio
384 * runtime (io.jstache.jstachio). However it is possible to generate code that does not
385 * need the runtime and possibly in the future other syntaxs like Handlebars might be
386 * supported.
387 *
388 * <h3 id="_methods_generated">Generated Renderer Classes</h3> JStachio generates a single
389 * class from a mustache template and model (class annotated with JStache) pair. The
390 * generated classes are generally called "Renderers" or sometimes "Templates". Depending
391 * on which JStache type is picked different methods are generated. The guaranteed
392 * generated methods <em>not to change on minor version or less</em> on the renderer
393 * classes are discussed in <strong>{@link JStacheType}</strong>.
394 *
395 * <h3 id="_zero_dep">Zero dependency code generation</h3>
396 *
397 * <strong>&#64;{@link io.jstach.jstache.JStacheConfig#type()} ==
398 * {@link JStacheType#STACHE}</strong>
399 * <p>
400 * Zero dependency code generation is useful if you want to avoid coupling your runtime
401 * and downstream dependencies with JStachio (including the annotations themselves) as
402 * well as minimize the overall footprint and or classes loaded. A common use case would
403 * be using jstachio for code generation in an annotation processing library where you
404 * want as minimal class path issues as possible.
405 * <p>
406 * If this configuration is selected generated code will <strong>ONLY have references to
407 * stock base JDK module ({@link java.base/}) classes</strong>. However one major caveat
408 * is that generated classes will not be reflectively accessible to the JStachio runtime
409 * and thus fallback and filtering will not work. Thus in a web framework environment this
410 * configuration choice is less desirable.
411 * <p>
412 * <em>n.b. as long as the jstachio annotations are not accessed reflectively you do not
413 * need the annotation jar in the classpath during runtime thus the annotations jar is
414 * effectively an optional compile time dependency.</em>
415 *
416 *
417 * <h2 id="_formatting">Formatting variables</h2>
418 *
419 * JStachio has strict control on what happens when you output a variable (a binding that
420 * is not an iterable) like <code>{{variable}}</code> or <code>{{{variable}}}</code>.
421 *
422 * <h3 id="_allowed_types">Allowed formatting types</h3> <strong>
423 * &#64;{@link io.jstach.jstache.JStacheFormatterTypes}</strong>
424 * <p>
425 * Only a certain set of types are allowed to be formatted and if they are not a compiler
426 * error will happen (as in the annotation processor will fail). To understand more about
427 * that see {@link io.jstach.jstache.JStacheFormatterTypes}.
428 *
429 * <h3 id="_runtime_formatting">Runtime formatting</h3>
430 * <strong>&#64;{@link io.jstach.jstache.JStacheFormatter} and
431 * &#64;{@link JStacheConfig#formatter()}</strong>
432 * <p>
433 * Assuming the compiler allowed the variable to be formatted you can control the output
434 * via {@link io.jstach.jstache.JStacheFormatter} and setting
435 * {@link io.jstach.jstache.JStacheConfig#formatter()}.
436 * <p>
437 * If you are using the JStachio runtime (io.jstach.jstachio) and have
438 * {@link JStacheConfig#type()} set to {@link JStacheType#JSTACHIO} (or UNSPECIFIED aka
439 * default) the default formatter will be used (see <code class=
440 * "externalLink">io.jstach.jstachio.formatters.DefaultFormatter</code>). The default
441 * formatter is slightly different than the mustache spec in that it does not allow
442 * formatting nulls. If you would like to follow the spec rules where <code>null</code>
443 * should be an empty string use <code class=
444 * "externalLink">io.jstach.jstachio.formatters.SpecFormatter</code>.
445 *
446 * <h2 id="_escaping">Escaping and Content Type</h2>
447 * <strong>&#64;{@link io.jstach.jstache.JStacheContentType}, and
448 * &#64;{@link JStacheConfig#contentType()} </strong>
449 * <p>
450 * If you are using the JStachio runtime (io.jstach.jstachio) and have
451 * {@link JStacheConfig#type()} set to {@link JStacheType#JSTACHIO} (or UNSPECIFIED aka
452 * default) you will get out of the box escaping for HTML (see
453 * <code class="externalLink">io.jstach.jstachio.escapers.Html</code>) per the mustache
454 * spec.
455 * <p>
456 * <strong>To disable escaping</strong> set {@link JStacheConfig#contentType()} to
457 * <code class="externalLink">io.jstach.jstachio.escapers.PlainText</code>.
458 *
459 * <h2 id="_config">Configuration</h2> <strong>&#64;{@link JStacheConfig}</strong>
460 * <p>
461 * You can set global configuration on class, packages and module elements. See
462 * {@link JStacheConfig} for more details on config resolution. Some configuration is set
463 * through compiler flags and annotation processor options. However {@link JStacheConfig}
464 * unlike compiler flags and annotation processor options are available during runtime
465 * through reflective access.
466 *
467 * <h3 id="_config_flags">Compiler flags</h3>
468 *
469 * The compiler has some boolean flags that can be set statically via {@link JStacheFlags}
470 * as well as through annotation processor options.
471 *
472 * <h3 id="_config_compiler">Annotation processor options</h3>
473 *
474 * Some configuration is available as an annotation processor option. Current available
475 * options are:
476 *
477 * <ul>
478 * <li>{@link #RESOURCES_PATH_OPTION}</li>
479 * </ul>
480 *
481 * The previously mentioned {@linkplain JStacheFlags compiler flags} are also available as
482 * annotation options. The flags are prefixed with "<code>jstache.</code>". For example
483 * {@link JStacheFlags.Flag#DEBUG} would be:
484 * <p>
485 * <code>jstache.debug=true/false</code>.
486 *
487 * <h4 id="_config_compiler_maven">Configuring options with Maven</h4>
488 *
489 * Example configuration with Maven:
490 *
491 * <pre class="language-xml">{@code
492 * <plugin>
493 *     <groupId>org.apache.maven.plugins</groupId>
494 *     <artifactId>maven-compiler-plugin</artifactId>
495 *     <version>3.8.1</version>
496 *     <configuration>
497 *         <source>17</source>
498 *         <target>17</target>
499 *         <annotationProcessorPaths>
500 *             <path>
501 *                 <groupId>io.jstach</groupId>
502 *                 <artifactId>jstachio-apt</artifactId>
503 *                 <version>${io.jstache.version}</version>
504 *             </path>
505 *         </annotationProcessorPaths>
506 *         <compilerArgs>
507 *             <arg>
508 *                 -Ajstache.resourcesPath=src/main/resources
509 *             </arg>
510  *             <arg>
511 *                 -Ajstache.debug=false
512 *             </arg>
513 *         </compilerArgs>
514 *     </configuration>
515 * </plugin>
516 * }</pre>
517 *
518 * <h4 id="_config_compiler_gradle">Configuring options with Gradle</h4>
519 *
520 * Example configuration with Gradle:
521 *
522 * <pre>
523 * <code class="language-kotlin">
524 * compileJava {
525 *     options.compilerArgs += [
526 *     '-Ajstache.resourcesPath=src/main/resources'
527 *     ]
528 * }
529 * </code> </pre>
530 *
531 *
532 * </div>
533 *
534 * @author agentgt
535 * @see JStachePath
536 * @see JStacheFormatterTypes
537 * @see JStacheConfig
538 * @see JStacheFormatter
539 * @see JStacheContentType
540 * @see JStacheConfig
541 *
542 * @jstachioVersion
543 */
544@Retention(RetentionPolicy.RUNTIME)
545@Target(ElementType.TYPE)
546@Documented
547public @interface JStache {
548
549        /**
550         * Resource path to template
551         * @return Path to mustache template
552         * @see JStachePath
553         */
554        String path() default "";
555
556        /**
557         * Inline the template as a Java string instead of a file. Use the new triple quote
558         * string literal for complex templates.
559         * @return An inline template
560         */
561        String template() default "";
562
563        /**
564         * Name of generated class.
565         * <p>
566         * name can be omitted. <code>model.getClass().getName()</code> +
567         * {@link JStacheName#DEFAULT_SUFFIX} name is used by default.
568         * @return Name of generated class
569         */
570        String name() default "";
571
572        /**
573         * An annotation processor compiler flag
574         * (<strong>{@value #RESOURCES_PATH_OPTION}</strong>) that says where the templates
575         * files are located.
576         * <p>
577         * When the annotation processor runs these files usually are in:
578         * <code>javax.tools.StandardLocation#CLASS_OUTPUT</code> and in a Maven or Gradle
579         * project they normally would reside in <code>src/main/resources</code> or
580         * <code>src/test/resources</code> which get copied on build to
581         * <code>target/classes</code> or similar. However due to incremental compiling
582         * template files are not always copied to <code>target/classes</code> and thus are
583         * not found by the annotation processor. To deal with this issue JStachio during
584         * compilation fallsback to direct filesystem access of the <em>source</em> directory
585         * instead of the output (<code>javax.tools.StandardLocation#CLASS_OUTPUT</code>) if
586         * the files cannot be found.
587         * <p>
588         * If the path does not start with a path separator then it will be appended to the
589         * the current working directory otherwise it is assumed to be a fully qualified path.
590         * <p>
591         * The default location is <code>CWD/src/main/resources</code> where CWD is the
592         * current working directory.
593         *
594         * <strong>If the option is blank or empty then NO fallback will happen and
595         * effectively disables the above behavior. </strong>
596         *
597         * You can change it by passing to the annotation processor a setting for
598         * <strong>{@value #RESOURCES_PATH_OPTION}</strong> like:
599         * <pre><code>jstache.resourcesPath=some/path</code></pre>
600         *
601         * For build annotation processor configuration examples see:
602         * <ol>
603         * <li><a href="#_config_compiler_maven">Configuring options with Maven</a></li>
604         * <li><a href="#_config_compiler_gradle">Configuring options with Gradle</a></li>
605         * </ol>
606         *
607         */
608        public static final String RESOURCES_PATH_OPTION = "jstache.resourcesPath";
609
610}