KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > template > StatementListTemplateParameter


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 (no returns).
11  *
12  * <p>
13  * To define a new statement list template parameter, you must subclass this
14  * class and implement the {@link #statements()} method, which actually defines
15  * the Java statements. It corresponds to a
16  * {@link spoon.reflect.code.CtStatementList}.
17  */

18 public abstract class StatementListTemplateParameter implements
19         TemplateParameterList<Void JavaDoc> {
20
21     /**
22      * Creates a new statement list template parameter.
23      */

24     public StatementListTemplateParameter() {
25     }
26
27     @SuppressWarnings JavaDoc("unchecked")
28     public CtStatementList<Void JavaDoc> 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<Void JavaDoc> 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 Void JavaDoc S() {
49         return null;
50     }
51
52     /**
53      * This method must be implemented to define the template statement list.
54      */

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