1 /**
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Intalio, Inc. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Intalio, Inc. Exolab is a registered
23 * trademark of Intalio, Inc.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved.
42 */
43 package org.exolab.javasource;
44
45 /**
46 * Defines methods for manipulating annotations held against various
47 * program code elements, such as classes, fields, methods etc. This interface
48 * is similar to the java.lang.reflect.AnnotatedElement except that it also
49 * allows modifications of associated annotations. It is implemented by the
50 * classes within this package that represent applicable code elements.
51 * <p>
52 * Adding the class annotations
53 * <pre>
54 * JClass lollipop = new JClass("Lollipop");
55 * JAnnotationType endorsersType = new JAnnotationType("Endorsers");
56 * JAnnotation endorsers = new JAnnotation(endorsersType);
57 * endorsers.setValue(new String[] { "\"Children\"", "\"Unscrupulous dentists\""});
58 * lollipop.addAnnotation(endorsers);
59 * </pre>
60 * outputs
61 * <pre>
62 * @Endorsers(
63 * {
64 * "Children",
65 * "Unscrupulous dentists"
66 * })
67 * public class Lollipop {
68 * }
69 * </pre>
70 * Adding the method annotations
71 * <pre>
72 * JClass timeMachine = new JClass("TimeMachine");
73 * JAnnotationType requestType = new JAnnotationType("RequestForEnhancement");
74 * JAnnotation request = new JAnnotation(requestType);
75 * request.setElementValue("id", "2868724");
76 * request.setElementValue("synopsis", "\"Provide time-travel functionality\"");
77 * request.setElementValue("engineer", "\"Mr. Peabody\"");
78 * request.setElementValue("date", "\"4/1/2004\"");
79 * JMethod travelThroughTime = new JMethod(null, "travelThroughTime");
80 * travelThroughTime.addAnnotation(request);
81 * travelThroughTime.addParameter(new JParameter(new JClass("Date"), "date"));
82 * timeMachine.addMethod(travelThroughTime);
83 * </pre>
84 * outputs
85 * <pre>
86 * @RequestForEnhancement(
87 * id = 2868724,
88 * synopsis = "Provide time-travel functionality",
89 * engineer = "Mr. Peabody",
90 * date = "4/1/2004")
91 * public void travelThroughTime(Date date)
92 * {
93 * }
94 * </pre>
95 * Adding the field annotations
96 * <pre>
97 * JClass timeMachine = new JClass("EventProducer");
98 * JAnnotationType suppressWarningsType = new JAnnotationType("SuppressWarnings");
99 * JAnnotation suppressWarnings = new JAnnotation(suppressWarningsType);
100 * JField field = new JField(new JClass("DocumentHandler"), "documentHandler");
101 * field.addAnnotation(suppressWarnings);
102 * timeMachine.addField(field);
103 * </pre>
104 * outputs
105 * <pre>
106 * @SuppressWarnings()
107 * private DocumentHandler documentHandler;
108 * </pre>
109 *
110 * @author <a href="mailto:andrew DOT fawcett AT coda DOTcom">Andrew Fawcett</a>
111 * @version $Revision$ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
112 */
113 public interface JAnnotatedElement {
114 //--------------------------------------------------------------------------
115
116 /**
117 * Retrieves a JAnnotation for the given JAnnotationType, returns null if no
118 * annotation has been set.
119 *
120 * @param annotationType Annotation type to retrieve.
121 * @return A JAnnotation for the given JAnnotationType.
122 */
123 JAnnotation getAnnotation(JAnnotationType annotationType);
124
125 /**
126 * Returns a list of JAnnotation's already set on this source element.
127 *
128 * @return A list of all JAnnotations associated with this source element.
129 */
130 JAnnotation[] getAnnotations();
131
132 /**
133 * Returns true if a JAnnotation exists for the given JAnnotationType.
134 *
135 * @param annotationType Annotation type to check for presence or absense.
136 * @return True if a JAnnotation has been added for the given JAnnotationType.
137 */
138 boolean isAnnotationPresent(JAnnotationType annotationType);
139
140 /**
141 * Adds a JAnnotation to this source element. An IllegalArgumentException is
142 * thrown if one already exists for the associated JAnnotationType.
143 *
144 * @param annotation A JAnnotation to add to this source element.
145 */
146 void addAnnotation(JAnnotation annotation);
147
148 /**
149 * Removes the JAnnotation from this source element for the given
150 * JAnnotationType. An IllegalArgumentException is thrown if the provided
151 * JAnnotation isn't present.
152 *
153 * @param annotationType Annotation type to remove.
154 * @return The JAnnotation that was associated with this source element.
155 */
156 JAnnotation removeAnnotation(JAnnotationType annotationType);
157
158 /**
159 * Returns true if this source element has any annotations.
160 *
161 * @return Returns true if this source element has any annotations.
162 */
163 boolean hasAnnotations();
164
165 //--------------------------------------------------------------------------
166 }