KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > examples > visitor > template > VisitorTemplate


1 package spoon.examples.visitor.template;
2
3 import spoon.template.Local;
4 import spoon.template.Parameter;
5 import spoon.template.Template;
6
7 /**
8  * The template {@link VisitorTemplate} defines an {@link #accept(_Visitor_)}
9  * template method to be introduced in a target visited class. It takes two
10  * parameters: {@link #_target_} is the simple name of the target visited class,
11  * and {@link #_Visitor_} is the actual type of the visitor.
12  */

13 public class VisitorTemplate implements Template {
14
15     /**
16      * The simple name of the target visited class.
17      */

18     @Parameter
19     String JavaDoc _target_;
20
21     /**
22      * The actual type of the visitor.
23      */

24     @Parameter
25     Class JavaDoc _Visitor_;
26
27     /**
28      * The template's constructor that binds its parameters.
29      */

30     @Local
31     public VisitorTemplate(String JavaDoc target, Class JavaDoc visitorType) {
32         _target_ = target;
33         _Visitor_ = visitorType;
34     }
35
36     /**
37      * The <code>accept</code> template method is the core of this template.
38      * It is simple since it just calls back the right visitation method on the
39      * passed visitor.
40      */

41     public void accept(_Visitor_ visitor) {
42         visitor.visit_target_(this);
43     }
44
45 }
46
Popular Tags