Package io.quarkus.qute
Annotation Type TemplateExtension
-
@Retention(RUNTIME) @Target({METHOD,TYPE}) public @interface TemplateExtension
Instructs a fully integrated environment to generate aValueResolverfor a method annotated with this annotation.If declared on a class a value resolver is generated for every non-private static method declared on the class. Method-level annotations override the behavior defined on the class. Methods that do not meet the following requirements are ignored.
A template extension method:
- must not be private,
- must be static,
- must not return
void.
TemplateExtension.TemplateAttributeis used to match the base object. Otherwise the namespace is used to match an expression.@TemplateExtension static BigDecimal discountedPrice(Item item) { // this method matches {item.discountedPrice} iff "item" resolves to an object assignable to "Item" return item.getPrice().multiply(new BigDecimal("0.9")); }By default, the method name is used to match the property name. However, it is possible to specify the matching name withmatchName().@TemplateExtension(matchName = "discounted") static BigDecimal discountedPrice(Item item) { // this method matches {item.discounted} iff "item" resolves to an object assignable to "Item" return item.getPrice().multiply(new BigDecimal("0.9")); }A special constant -ANY- may be used to specify that the extension method matches any name. It is also possible to match the name against a regular expression specified inmatchRegex(). In both cases, an additional string method parameter must be used to pass the property name. If bothmatchName()andmatchRegex()are set the regular expression is used for matching.@TemplateExtension(matchName = "*") static String itemProperty(Item item, String name) { // this method matches {item.foo} iff "item" resolves to an object assignable to "Item" // the value of the "name" parameter is "foo" }
-
-
Field Summary
Fields Modifier and Type Fields Description static StringANYConstant value formatchName()indicating that any name matches.static intDEFAULT_PRIORITYConstant value for {priority().static StringMETHOD_NAMEConstant value formatchName()indicating that the method name should be used.
-
-
-
Field Detail
-
METHOD_NAME
static final String METHOD_NAME
Constant value formatchName()indicating that the method name should be used.
-
-
-
ANY
static final String ANY
Constant value formatchName()indicating that any name matches.
-
-
-
DEFAULT_PRIORITY
static final int DEFAULT_PRIORITY
Constant value for {priority().
-
-
Element Detail
-
matchName
String matchName
- Returns:
- the name is used to match the property name
- Default:
- "<<method name>>"
-
-
-
matchRegex
String matchRegex
- Returns:
- the regex is used to match the property name
- Default:
- ""
-
-
-
namespace
String namespace
If not empty a namespace resolver is generated instead.Template extension methods that share the same namespace and are declared on the same class are grouped in one resolver and ordered by
priority(). The first matching extension method is used to resolve an expression. Template extension methods declared on different classes cannot share the same namespace.- Returns:
- the namespace
- See Also:
NamespaceResolver.getNamespace()
- Default:
- ""
-
-