01: /*
02: * Spoon - http://spoon.gforge.inria.fr/
03: * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
04: *
05: * This software is governed by the CeCILL-C License under French law and
06: * abiding by the rules of distribution of free software. You can use, modify
07: * and/or redistribute the software under the terms of the CeCILL-C license as
08: * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
09: *
10: * This program is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
13: *
14: * The fact that you are presently reading this means that you have had
15: * knowledge of the CeCILL-C license and that you accept its terms.
16: */
17:
18: package spoon.template;
19:
20: import spoon.reflect.code.CtBlock;
21: import spoon.reflect.code.CtStatementList;
22: import spoon.reflect.declaration.CtClass;
23: import spoon.reflect.declaration.CtSimpleType;
24:
25: /**
26: * This class represents a template parameter that defines a statement list
27: * directly expressed in Java (no returns).
28: *
29: * <p>
30: * To define a new statement list template parameter, you must subclass this
31: * class and implement the {@link #statements()} method, which actually defines
32: * the Java statements. It corresponds to a
33: * {@link spoon.reflect.code.CtStatementList}.
34: */
35: public abstract class StatementListTemplateParameter implements
36: TemplateParameterList<Void> {
37:
38: /**
39: * Creates a new statement list template parameter.
40: */
41: public StatementListTemplateParameter() {
42: }
43:
44: @SuppressWarnings("unchecked")
45: public CtStatementList<Void> getSubstitution(
46: CtSimpleType<?> targetType) {
47: CtClass<?> c;
48: CtBlock<?> b;
49: c = targetType.getFactory().Template().get(this .getClass());
50: if (c == null) {
51: c = targetType.getFactory().Class().get(this .getClass());
52: }
53: CtStatementList<Void> l = targetType.getFactory().Core()
54: .createStatementList();
55: if (this instanceof Template) {
56: b = Substitution.substitute(targetType, (Template) this , c
57: .getMethod("statements").getBody());
58: } else {
59: b = targetType.getFactory().Core().clone(
60: c.getMethod("statements").getBody());
61: }
62: l.setStatements(b.getStatements());
63: return l;
64: }
65:
66: public Void S() {
67: return null;
68: }
69:
70: /**
71: * This method must be implemented to define the template statement list.
72: */
73: public abstract void statements() throws Throwable;
74: }
|