Interface JAnnotatedElement

All Known Implementing Classes:
AbstractJClass, AbstractJField, DescriptorJClass, JAnnotatedElementHelper, JAnnotationType, JClass, JConstant, JConstructor, JDODescriptorJClass, JEnum, JEnumConstant, JField, JInnerClass, JInterface, JMethod, JMethodSignature, JParameter, JStructure

public interface JAnnotatedElement
Defines methods for manipulating annotations held against various program code elements, such as classes, fields, methods etc. This interface is similar to the java.lang.reflect.AnnotatedElement except that it also allows modifications of associated annotations. It is implemented by the classes within this package that represent applicable code elements.

Adding the class annotations

 JClass lollipop = new JClass("Lollipop");
 JAnnotationType endorsersType = new JAnnotationType("Endorsers");
 JAnnotation endorsers = new JAnnotation(endorsersType);
 endorsers.setValue(new String[] {"\"Children\"", "\"Unscrupulous dentists\""});
 lollipop.addAnnotation(endorsers);
 
outputs
 @Endorsers({"Children", "Unscrupulous dentists"})
 public class Lollipop {
 }
 
Adding the method annotations
 JClass timeMachine = new JClass("TimeMachine");
 JAnnotationType requestType = new JAnnotationType("RequestForEnhancement");
 JAnnotation request = new JAnnotation(requestType);
 request.setElementValue("id", "2868724");
 request.setElementValue("synopsis", "\"Provide time-travel functionality\"");
 request.setElementValue("engineer", "\"Mr. Peabody\"");
 request.setElementValue("date", "\"4/1/2004\"");
 JMethod travelThroughTime = new JMethod(null, "travelThroughTime");
 travelThroughTime.addAnnotation(request);
 travelThroughTime.addParameter(new JParameter(new JClass("Date"), "date"));
 timeMachine.addMethod(travelThroughTime);
 
outputs
 @RequestForEnhancement(id = 2868724, synopsis = "Provide time-travel functionality",
     engineer = "Mr. Peabody", date = "4/1/2004")
 public void travelThroughTime(Date date) {}
 
Adding the 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
 @SuppressWarnings()
 private DocumentHandler documentHandler;
 
Version:
$Revision$ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
Author:
Andrew Fawcett