001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.mirror.apt;
027:
028: import com.sun.mirror.apt.*;
029: import java.util.*;
030:
031: /**
032: * Utilities to create specialized annotation processors.
033: *
034: * @since 1.5
035: * @author Joseph D. Darcy
036: * @author Scott Seligman
037: */
038: public class AnnotationProcessors {
039: static class NoOpAP implements AnnotationProcessor {
040: NoOpAP() {
041: }
042:
043: public void process() {
044: }
045: }
046:
047: /**
048: * Combines multiple annotation processors into a simple composite
049: * processor.
050: * The composite processor functions by invoking each of its component
051: * processors in sequence.
052: */
053: static class CompositeAnnotationProcessor implements
054: AnnotationProcessor {
055:
056: private List<AnnotationProcessor> aps = new LinkedList<AnnotationProcessor>();
057:
058: /**
059: * Constructs a new composite annotation processor.
060: * @param aps the component annotation processors
061: */
062: public CompositeAnnotationProcessor(
063: Collection<AnnotationProcessor> aps) {
064: this .aps.addAll(aps);
065: }
066:
067: /**
068: * Constructs a new composite annotation processor.
069: * @param aps the component annotation processors
070: */
071: public CompositeAnnotationProcessor(AnnotationProcessor... aps) {
072: for (AnnotationProcessor ap : aps)
073: this .aps.add(ap);
074: }
075:
076: /**
077: * Invokes the <tt>process</tt> method of each component processor,
078: * in the order in which the processors were passed to the constructor.
079: */
080: public void process() {
081: for (AnnotationProcessor ap : aps)
082: ap.process();
083: }
084: }
085:
086: /**
087: * An annotation processor that does nothing and has no state.
088: * May be used multiple times.
089: *
090: * @since 1.5
091: */
092: public final static AnnotationProcessor NO_OP = new NoOpAP();
093:
094: /**
095: * Constructs a new composite annotation processor. A composite
096: * annotation processor combines multiple annotation processors
097: * into one and functions by invoking each of its component
098: * processors' process methods in sequence.
099: *
100: * @param aps The processors to create a composite of
101: * @since 1.5
102: */
103: public static AnnotationProcessor getCompositeAnnotationProcessor(
104: AnnotationProcessor... aps) {
105: return new CompositeAnnotationProcessor(aps);
106: }
107:
108: /**
109: * Constructs a new composite annotation processor. A composite
110: * annotation processor combines multiple annotation processors
111: * into one and functions by invoking each of its component
112: * processors' process methods in the sequence the processors are
113: * returned by the collection's iterator.
114: *
115: * @param aps A collection of processors to create a composite of
116: * @since 1.5
117: */
118: public static AnnotationProcessor getCompositeAnnotationProcessor(
119: Collection<AnnotationProcessor> aps) {
120: return new CompositeAnnotationProcessor(aps);
121: }
122: }
|