1 package spoon.template; 2 3 import spoon.reflect.declaration.CtType; 4 5 /** 6 * This maker interface should be implemented by the classes containing some 7 * template code, so that they can be used as template parameter values holder 8 * for the {@link Substitution} methods. 9 * 10 * <p> A template code is simply a piece of code that uses a 11 * {@link TemplateParameter}'s instance. It must then invoke the 12 * {@link TemplateParameter#S()} method. 13 * 14 * <p>When the template parameter is a String or a primitive type (or a boxing 15 * type) representing a literal, or a Class, the template parameter can be 16 * directly accessed. 17 * 18 * <pre> 19 * import spoon.template.Template; 20 * import spoon.template.Value; 21 * 22 * public class SimpleTemplate implements Template { 23 * // template parameter fields 24 * @Parameter String _parameter_; 25 * 26 * // parameters binding 27 * @Local 28 * public SimpleTemplate(String parameter) { 29 * _parameter_ = parameter; 30 * } 31 * 32 * // template method 33 * public void simpleTemplateMethod() { 34 * System.out.println(_parameter_); 35 * } 36 * } 37 * </pre> 38 * 39 * <p>The template parameters must be bound to their values in the template's 40 * constructor (which should be defined as a template's 41 * {@link spoon.template.Local}. A possible use of a template would 42 * be to insert the template into a target class, by using 43 * {@link Substitution#insertAll(CtType,Template)}: 44 * 45 * <pre> 46 * spoon.reflect.CtClass target=...; 47 * Template template=new SimpleTemplate("hello templated world"); 48 * Substitution.insertAll(target,template); 49 * </pre> 50 * 51 * <p> If the target class is an empty class named <code>A</code>, the resulting code will 52 * be: 53 * 54 * <pre> 55 * public class A { 56 * public void insertedMethod() { 57 * System.out.println("hello templated world"); 58 * } 59 * } 60 * </pre> 61 * 62 */ 63 public interface Template {} 64