KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > examples > stack > template > BoundTestTemplate


1 package spoon.examples.stack.template;
2
3 import java.util.Collection JavaDoc;
4
5 import spoon.reflect.declaration.CtSimpleType;
6 import spoon.template.Local;
7 import spoon.template.Parameter;
8 import spoon.template.StatementListTemplateParameter;
9 import spoon.template.Template;
10
11 /**
12  * The {@link BoundTestTemplate} class shown below defines the code that tests
13  * that the stack <code>elements</code> do not exceed a given size, given by a
14  * <code>bound</code> integer. It subclasses
15  * {@link spoon.template.StatementListTemplateParameter} that allows the direct
16  * definition of the test within the
17  * {@link spoon.template.StatementListTemplateParameter#statements()} method.
18  * The substitution of this code will be returned when invoking
19  * {@link spoon.template.TemplateParameter#getSubstitution(CtSimpleType)} on an
20  * instance of the template, which avoid having to explicitly resolve the
21  * template method and substitutes its body.
22  */

23 public class BoundTestTemplate extends StatementListTemplateParameter implements
24         Template {
25
26     @Parameter
27     public int _bound_;
28
29     @Local
30     Collection JavaDoc elements;
31
32     public BoundTestTemplate(int bound) {
33         _bound_ = bound;
34     }
35
36     public void statements() throws StackFullException {
37         if (elements.size() >= _bound_) {
38             throw new StackFullException();
39         }
40     }
41 }
42
Popular Tags