KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > mirror > apt > AnnotationProcessors


1 /**
2  * @(#)AnnotationProcessors.java 1.2 04/06/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.mirror.apt;
9
10 import com.sun.mirror.apt.*;
11 import java.util.*;
12
13 /**
14  * Utilities to create specialized annotation processors.
15  *
16  * @since 1.5
17  * @author Joseph D. Darcy
18  * @author Scott Seligman
19  */

20 public class AnnotationProcessors {
21     static class NoOpAP implements AnnotationProcessor {
22     NoOpAP() {}
23     public void process(){}
24     }
25
26     /**
27      * Combines multiple annotation processors into a simple composite
28      * processor.
29      * The composite processor functions by invoking each of its component
30      * processors in sequence.
31      */

32     static class CompositeAnnotationProcessor implements AnnotationProcessor {
33     
34     private List<AnnotationProcessor> aps =
35         new LinkedList<AnnotationProcessor>();
36
37     /**
38      * Constructs a new composite annotation processor.
39      * @param aps the component annotation processors
40      */

41     public CompositeAnnotationProcessor(Collection<AnnotationProcessor> aps) {
42         this.aps.addAll(aps);
43     }
44
45     /**
46      * Constructs a new composite annotation processor.
47      * @param aps the component annotation processors
48      */

49     public CompositeAnnotationProcessor(AnnotationProcessor... aps) {
50         for(AnnotationProcessor ap: aps)
51         this.aps.add(ap);
52     }
53
54     /**
55      * Invokes the <tt>process</tt> method of each component processor,
56      * in the order in which the processors were passed to the constructor.
57      */

58     public void process() {
59         for(AnnotationProcessor ap: aps)
60         ap.process();
61     }
62     }
63  
64
65     /**
66      * An annotation processor that does nothing and has no state.
67      * May be used multiple times.
68      *
69      * @since 1.5
70      */

71     public final static AnnotationProcessor NO_OP = new NoOpAP();
72  
73     /**
74      * Constructs a new composite annotation processor. A composite
75      * annotation processor combines multiple annotation processors
76      * into one and functions by invoking each of its component
77      * processors' process methods in sequence.
78      *
79      * @param aps The processors to create a composite of
80      * @since 1.5
81      */

82     public static AnnotationProcessor getCompositeAnnotationProcessor(AnnotationProcessor... aps) {
83     return new CompositeAnnotationProcessor(aps);
84     }
85  
86     /**
87      * Constructs a new composite annotation processor. A composite
88      * annotation processor combines multiple annotation processors
89      * into one and functions by invoking each of its component
90      * processors' process methods in the sequence the processors are
91      * returned by the collection's iterator.
92      *
93      * @param aps A collection of processors to create a composite of
94      * @since 1.5
95      */

96     public static AnnotationProcessor getCompositeAnnotationProcessor(Collection<AnnotationProcessor> aps) {
97     return new CompositeAnnotationProcessor(aps);
98     }
99 }
100
101
102
103
Popular Tags