1 package spoon.template; 2 3 import java.lang.annotation.ElementType; 4 import java.lang.annotation.Retention; 5 import java.lang.annotation.RetentionPolicy; 6 import java.lang.annotation.Target; 7 8 import spoon.support.template.DefaultParameterMatcher; 9 import spoon.support.template.ParameterMatcher; 10 11 /** 12 * This annotation should be placed on templates' fields or methods to indicate 13 * that they represent template parameters. It is only mandatory for names, 14 * literals, and types, where it avoids having to use 15 * {@link spoon.template.TemplateParameter} and allows for the direct accesses 16 * of the parameters. A parameter is never considered as a templated element and 17 * it is not necessary to annotate it with a {@link Local} annotation. 18 */ 19 @Retention(RetentionPolicy.RUNTIME) 20 @Target( { 21 ElementType.FIELD, ElementType.METHOD 22 }) 23 public @interface Parameter { 24 /** 25 * Defines the name of the parameter (optional, mostly to avoid name 26 * clashes). By default, the name of a template parameter is the simple name 27 * of the annotated field. However, in some cases, it can be useful to set a 28 * different name to a parameter in order to avoid name clashes, in 29 * particular when a parameter represents the name of a templated field. For 30 * instance: 31 * 32 * <pre> 33 * class T extends Template { 34 * // this parameter will contain the actual value of the _i_ field's name 35 * @Parameter("_i_") 36 * String __i_; 37 * 38 * int _i_; 39 * } 40 * </pre> 41 */ 42 String value() default ""; 43 44 /** 45 * Precises the type of the parameter matcher for this particular parameter 46 * when using the {@link spoon.template.TemplateMatcher} engine (optional). By 47 * default, the parameter will match under any form. Specifying an 48 * implementation of {@link ParameterMatcher} here allows the matching of 49 * more specific forms. 50 */ 51 Class<? extends ParameterMatcher> match() default DefaultParameterMatcher.class; 52 } 53