KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > template > TypedBlockTemplateParameter


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

17 public abstract class TypedBlockTemplateParameter<R> implements
18         TemplateParameter<R> {
19
20     /**
21      * Creates a new block template parameter.
22      */

23     public TypedBlockTemplateParameter() {
24     }
25
26     /**
27      * This method must be implemented to define the template block.
28      */

29     public abstract R block() throws Throwable JavaDoc;
30
31     @SuppressWarnings JavaDoc("unchecked")
32     public CtBlock<R> getSubstitution(CtSimpleType targetType) {
33         CtClass<?> c;
34         c= targetType.getFactory().Template().get(this.getClass());
35         if(c==null) {
36             c=targetType.getFactory().Class().get(this.getClass());
37         }
38         CtMethod<R> m = (CtMethod<R>) c.getMethod("block");
39         if (this instanceof Template) {
40             return Substitution.substitute(targetType, (Template) this, m
41                     .getBody());
42         } else {
43             return targetType.getFactory().Core().clone(m.getBody());
44         }
45     }
46
47     public R S() {
48         return null;
49     }
50 }
51
Popular Tags