KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > template > TypedStatementListTemplateParameter


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

19 public abstract class TypedStatementListTemplateParameter<R> implements
20         TemplateParameterList<R> {
21
22     /**
23      * Creates a new statement list template parameter.
24      */

25     public TypedStatementListTemplateParameter() {
26     }
27
28     public CtStatementList<R> getSubstitution(CtSimpleType targetType) {
29         CtClass<?> c;
30         CtBlock<?> b;
31         c= targetType.getFactory().Template().get(this.getClass());
32         if(c==null) {
33             c=targetType.getFactory().Class().get(this.getClass());
34         }
35         CtStatementList<R> l = targetType.getFactory().Core()
36                 .createStatementList();
37         if (this instanceof Template) {
38             b = Substitution.substitute(targetType, (Template) this, c
39                     .getMethod("statements").getBody());
40         } else {
41             b = targetType.getFactory().Core().clone(c.getMethod("statements")
42                     .getBody());
43         }
44         l.setStatements(b.getStatements());
45         return l;
46     }
47
48     public R S() {
49         return null;
50     }
51
52     /**
53      * This method must be implemented to define the template statement list.
54      */

55     public abstract R statements() throws Throwable JavaDoc;
56 }
57
Popular Tags