KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > template > BlockTemplateParameter


1 package spoon.template;
2
3 import spoon.reflect.code.CtBlock;
4 import spoon.reflect.declaration.CtClass;
5 import spoon.reflect.declaration.CtSimpleType;
6
7 /**
8  * This class represents a template parameter that defines a void block
9  * statement directly expressed in Java (no returns).
10  *
11  * <p>
12  * To define a new block template parameter, you must subclass this class and
13  * implement the {@link #block()} method, which actually defines the Java block.
14  * It corresponds to a {@link spoon.reflect.code.CtBlock}.
15  */

16 public abstract class BlockTemplateParameter implements TemplateParameter<Void JavaDoc> {
17
18     /**
19      * Creates a new block template parameter.
20      */

21     public BlockTemplateParameter() {
22     }
23
24     public CtBlock<?> getSubstitution(CtSimpleType<?> targetType) {
25         CtClass<?> c;
26         c= targetType.getFactory().Template().get(this.getClass());
27         if(c==null) {
28             c=targetType.getFactory().Class().get(this.getClass());
29         }
30         if (this instanceof Template) {
31             return Substitution.substitute(targetType, (Template) this, c
32                     .getMethod("block").getBody());
33         } else {
34             return targetType.getFactory().Core().clone(c.getMethod("block")
35                     .getBody());
36         }
37     }
38
39     public Void JavaDoc S() {
40         return null;
41     }
42
43     /**
44      * This method must be implemented to define the template block.
45      */

46     public abstract void block() throws Throwable JavaDoc;
47 }
48
Popular Tags