org.exolab.javasource
public interface JAnnotatedElement
UNKNOWN: { "Children", "Unscrupulous dentists" }) public class Lollipop { } Adding method annotations JClass timeMachine = new JClass("TimeMachine"); JAnnotationType requestForEnhancementType = new JAnnotationType("RequestForEnhancement"); JAnnotation requestForEnhancement = new JAnnotation(requestForEnhancementType); requestForEnhancement.setElementValue("id", "2868724"); requestForEnhancement.setElementValue("sysopsis", "\"Provide time-travel functionality\""); requestForEnhancement.setElementValue("enginer", "\"Mr. Peabody\""); requestForEnhancement.setElementValue("date", "\"4/1/2004\""); JMethod travelThroughTime = new JMethod(null, "travelThroughTime"); travelThroughTime.addAnnotation(requestForEnhancement); travelThroughTime.addParameter(new JParameter(new JClass("Date"), "date")); timeMachine.addMethod(travelThroughTime); Outputs id = 2868724, sysopsis = "Provide time-travel functionality", enginer = "Mr. Peabody", date = "4/1/2004") public void travelThroughTime(Date date) { } Adding field annotations JClass timeMachine = new JClass("EventProducer"); JAnnotationType suppressWarningsType = new JAnnotationType("SuppressWarnings"); JAnnotation suppressWarnings = new JAnnotation(suppressWarningsType); JField field = new JField(new JClass("DocumentHandler"), "documentHandler"); field.addAnnotation(suppressWarnings); timeMachine.addField(field); Outputs private DocumentHandler documentHandler;
Method Summary | |
---|---|
void | addAnnotation(JAnnotation annotation)
Adds a JAnnotation to this source element. |
JAnnotation | getAnnotation(JAnnotationType annotationType)
Retrieves a JAnnotation for the given JAnnotationType, returns null
if no annotation has been set. |
JAnnotation[] | getAnnotations()
Returns a list of JAnnotation's already set on this source element |
boolean | hasAnnotations()
Returns true if annotations have been added to this source element |
boolean | isAnnotationPresent(JAnnotationType annotationType)
Returns true if a JAnnotation exists for the given JAnnotationType |
JAnnotation | removeAnnotation(JAnnotationType annotationType)
Removes the JAnnotation from this source element for the given JAnnotationType,
throws a IllegalArgumentException if no JAnnotation has been added. |
Parameters: annotation
Parameters: annotationType
Returns: A JAnnotation for the given JAnnotationType
Returns: A list of all JAnnotations associated with this source element
Returns: Returns true if annotations have been added to this source element
Parameters: annotationType
Returns: True if a JAnnotation has been added for the given JAnnotationType
Parameters: annotationType
Returns: The JAnnotation that was associated with this source element