KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > examples > stack > processing > BoundProcessor


1 package spoon.examples.stack.processing;
2
3 import spoon.examples.stack.annotation.Bound;
4 import spoon.examples.stack.template.BoundTestTemplate;
5 import spoon.examples.stack.template.StackFullException;
6 import spoon.processing.AbstractAnnotationProcessor;
7 import spoon.reflect.declaration.CtClass;
8 import spoon.reflect.declaration.CtMethod;
9
10 /**
11  * This processor (see the code below) processes the
12  * {@link spoon.examples.stack.annotation.Bound} annotation and uses
13  * {@link spoon.examples.stack.template.BoundTestTemplate} to insert a test on
14  * the bound in the <code>push</code> method.
15  */

16 public class BoundProcessor extends
17         AbstractAnnotationProcessor<Bound, CtClass<?>> {
18
19     public void process(Bound b, CtClass<?> c) {
20         CtMethod<?> m = c.getMethod("push", getFactory().Type()
21                 .createTypeParameterReference("T"));
22         BoundTestTemplate template = new BoundTestTemplate(b.max());
23         m.getBody().insertBegin(template.getSubstitution(c));
24         m.getThrownTypes().add(
25                 getFactory().Type().createReference(StackFullException.class));
26     }
27 }
28
Popular Tags