Public Member Functions

org.exolab.javasource.JAnnotatedElement Interface Reference

Inheritance diagram for org.exolab.javasource.JAnnotatedElement:
org.exolab.javasource.JMethod org.exolab.javasource.JStructure org.exolab.javasource.JAnnotationType org.exolab.javasource.JClass org.exolab.javasource.JInterface org.exolab.castor.builder.util.DescriptorJClass org.exolab.javasource.JClass.JInnerClass

List of all members.

Public Member Functions

JAnnotation getAnnotation (JAnnotationType annotationType)
JAnnotation[] getAnnotations ()
boolean isAnnotationPresent (JAnnotationType annotationType)
void addAnnotation (JAnnotation annotation) throws IllegalArgumentException
JAnnotation removeAnnotation (JAnnotationType annotationType) throws IllegalArgumentException
boolean hasAnnotations ()

Detailed Description

Interface defines methods for manipuling annotations held against various program code elements, such as classes, fields, methods etc. This interface is simalar to the java.lang.reflect.AnnotatedElement. Accept that it also allows modifications of associated annotations. It is implemented by the classes within this package that represent applicable code elements.

Adding 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

( { "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;

Author:
Andrew Fawcett

Member Function Documentation

void org.exolab.javasource.JAnnotatedElement.addAnnotation ( JAnnotation  annotation  )  throws IllegalArgumentException

Adds a JAnnotation to this source element. An IllegalArgumentException is thrown if one already exists for the associated JAnnotationType.

Parameters:
annotation 

Implemented in org.exolab.javasource.JMethod, and org.exolab.javasource.JStructure.

JAnnotation org.exolab.javasource.JAnnotatedElement.getAnnotation ( JAnnotationType  annotationType  ) 

Retrieves a JAnnotation for the given JAnnotationType, returns null if no annotation has been set.

Parameters:
annotationType 
Returns:
A JAnnotation for the given JAnnotationType

Implemented in org.exolab.javasource.JMethod, and org.exolab.javasource.JStructure.

JAnnotation [] org.exolab.javasource.JAnnotatedElement.getAnnotations (  ) 

Returns a list of JAnnotation's already set on this source element

Returns:
A list of all JAnnotations associated with this source element

Implemented in org.exolab.javasource.JMethod, and org.exolab.javasource.JStructure.

boolean org.exolab.javasource.JAnnotatedElement.hasAnnotations (  ) 

Returns true if annotations have been added to this source element

Returns:
Returns true if annotations have been added to this source element

Implemented in org.exolab.javasource.JMethod, and org.exolab.javasource.JStructure.

boolean org.exolab.javasource.JAnnotatedElement.isAnnotationPresent ( JAnnotationType  annotationType  ) 

Returns true if a JAnnotation exists for the given JAnnotationType

Parameters:
annotationType 
Returns:
True if a JAnnotation has been added for the given JAnnotationType

Implemented in org.exolab.javasource.JMethod, and org.exolab.javasource.JStructure.

JAnnotation org.exolab.javasource.JAnnotatedElement.removeAnnotation ( JAnnotationType  annotationType  )  throws IllegalArgumentException

Removes the JAnnotation from this source element for the given JAnnotationType, throws a IllegalArgumentException if no JAnnotation has been added.

Parameters:
annotation 
Returns:
The JAnnotation that was associated with this source element

Implemented in org.exolab.javasource.JMethod, and org.exolab.javasource.JStructure.


The documentation for this interface was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties