AbstractJClass
, AbstractJField
, DescriptorJClass
, JAnnotatedElementHelper
, JAnnotationType
, JClass
, JConstant
, JConstructor
, JDODescriptorJClass
, JEnum
, JEnumConstant
, JField
, JInnerClass
, JInterface
, JMethod
, JMethodSignature
, JParameter
, JStructure
public interface JAnnotatedElement
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;
Modifier and Type | Method | Description |
---|---|---|
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 this source element has any annotations.
|
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.
|
JAnnotation getAnnotation(JAnnotationType annotationType)
annotationType
- Annotation type to retrieve.JAnnotation[] getAnnotations()
boolean isAnnotationPresent(JAnnotationType annotationType)
annotationType
- Annotation type to check for presence or absense.void addAnnotation(JAnnotation annotation)
annotation
- A JAnnotation to add to this source element.JAnnotation removeAnnotation(JAnnotationType annotationType)
annotationType
- Annotation type to remove.boolean hasAnnotations()
Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com