org.exolab.javasource
public class JAnnotation extends Object
UNKNOWN: For "Single Element Annotation", construct as above and call the setValue(value) method to set the value of the "value" element of the annotation type. JAnnotationType copyrightType = new JAnnotationType("Copyright"); JAnnotation copyright = new JAnnotation(copyrightType); copyright.setValue("\"2002 Yoyodyne Propulsion Systems, Inc., All rights reserved.\""); Outputs Yoyodyne Propulsion Systems, Inc., All rights reserved.") For "Normal Annotation", construct as above then call the approprite setValue methods that accept an "elementName" parameter. 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\""); Outputs id = 2868724, sysopsis = "Provide time-travel functionality", enginer = "Mr. Peabody", date = "4/1/2004") "Complex" annotations are also supported via the various setValue methods that take a JAnnotation object. JAnnotationType nameType = new JAnnotationType("Name"); JAnnotationType authorType = new JAnnotationType("Author"); JAnnotation author = new JAnnotation(authorType); JAnnotation name = new JAnnotation(nameType); name.setElementValue("first", "\"Joe\""); name.setElementValue("last", "\"Hacker\""); author.setValue(name); Outputs first = "Joe", last = "Hacker")) Finally annotation elements who's types are arrays are supported via the setValue methods that take arrays. JAnnotationType endorsersType = new JAnnotationType("Endorsers"); JAnnotation endorsers = new JAnnotation(endorsersType); endorsers.setValue(new String[] { "\"Children\"", "\"Unscrupulous dentists\""}); Outputs { "Children", "Unscrupulous dentists" }) Note: Conditional element values are not currently supported. However the setValue methods taking String values can be used to output this construct literally if desired.
Field Summary | |
---|---|
static String | value
Name of a single element |
Constructor Summary | |
---|---|
JAnnotation(JAnnotationType annotationType)
Constructs a JAnnotation for the given annotation type |
Method Summary | |
---|---|
JAnnotationType | getAnnotationType()
Returns the JAnnotationType associated with this JAnnotation |
String[] | getElementNames()
Returns the names of the elements set by this annotation |
String | getElementValue(String elementName)
Returns the given annotation element value |
JAnnotation | getElementValueAnnotation(String elementName)
Returns the given annotation element value as a JAnnotation |
JAnnotation[] | getElementValueAnnotationList(String elementName)
Returns the given annotation element value as a JAnnotation list |
String[] | getElementValueList(String elementName)
Returns the given annotation element value as a list |
Object | getElementValueObject(String elementName)
Returns the given annotation element value as Object, typically used
if the value type is not known. |
String | getValue()
Returns the "value" annotation element value |
JAnnotation | getValueAnnotation()
Returns the "value" annotation element value as an JAnnotation |
static void | main(String[] args)
Test |
void | print(JSourceWriter jsw)
Prints the source code for this JAnnotation to the given JSourceWriter |
void | setElementValue(String elementName, String stringValue)
Sets the given annotation element value |
void | setElementValue(String elementName, String[] stringValues)
Sets the given annotation element value as a list |
void | setElementValue(String elementName, JAnnotation annotationValue)
Sets the given annotation element value as an annotation |
void | setElementValue(String elementName, JAnnotation[] annotationValues)
Sets the given annotation element values as a list of annotation values |
void | setValue(String stringValue)
Sets the "value" annotation element value |
void | setValue(String[] stringValue)
Sets the "value" annotation element value as a list |
void | setValue(JAnnotation annotationValue)
Sets the "value" annotation element value as an annotation |
void | setValue(JAnnotation[] annotationValues)
Sets the "value" annotation element value as a list of annotation values |
Parameters: annotationType
Returns: array of element names
Parameters: elementName
Returns:
Throws: IllegalArgumentException when the element value is not a String
Parameters: elementName
Returns: annotation element value as a JAnnotation
Throws: IllegalArgumentException when the element value is not a JAnnotation
Parameters: elementName
Returns:
Throws: IllegalArgumentException when the element value is not a JAnnotation[]
Parameters: elementName
Returns:
Throws: IllegalArgumentException when the element value is not a String[]
Parameters: elementName
Returns: annotation element value as Object
Returns:
Throws: IllegalStateException when the element value is not a String
Returns:
Throws: IllegalStateException when the element value is not a JAnnotation
Parameters: args
Parameters: jsw the JSourceWriter to print to. [May not be null]
Parameters: elementName stringValue
Parameters: elementName stringValues
Parameters: elementName annotationValue
Parameters: elementName annotationValues
Parameters: stringValue
Parameters: stringValue
Parameters: annotationValue
Parameters: annotationValues