Public Member Functions | |
JAnnotation (JAnnotationType annotationType) | |
JAnnotationType | getAnnotationType () |
void | setValue (String stringValue) |
void | setValue (String[] stringValue) |
void | setValue (JAnnotation annotationValue) |
void | setValue (JAnnotation[] annotationValues) |
void | setElementValue (String elementName, String stringValue) |
void | setElementValue (String elementName, String[] stringValues) |
void | setElementValue (String elementName, JAnnotation annotationValue) |
void | setElementValue (String elementName, JAnnotation[] annotationValues) |
String | getValue () |
JAnnotation | getValueAnnotation () throws IllegalStateException |
String | getElementValue (String elementName) throws IllegalStateException |
String[] | getElementValueList (String elementName) throws IllegalStateException |
Object | getElementValueObject (String elementName) |
JAnnotation | getElementValueAnnotation (String elementName) throws IllegalStateException |
JAnnotation[] | getElementValueAnnotationList (String elementName) throws IllegalStateException |
String[] | getElementNames () |
void | print (JSourceWriter jsw) |
Static Public Member Functions | |
static void | main (String[] args) |
Static Public Attributes | |
static final String | value = "value" |
JAnnotation represents a single annotation against a code element. The methods described on the JAnnotatedElement interface are used to associate JAnnotation's with various other objects in this package describing Java code elements.
The print method outputs annotations in various forms (as described in the Java Language Specificaiton Third Edition) based on the methods called.
For "Marker Annotation", construct with the approprite JAnnotationType.
JAnnotationType preliminaryType = new JAnnotationType("Preliminary"); JAnnotation preliminary = new JAnnotation(preliminaryType);
Outputs
()
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
("2002 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.
org.exolab.javasource.JAnnotation.JAnnotation | ( | JAnnotationType | annotationType | ) |
Constructs a JAnnotation for the given annotation type
annotationType |
Referenced by org.exolab.javasource.JAnnotation.main().
JAnnotationType org.exolab.javasource.JAnnotation.getAnnotationType | ( | ) |
Returns the JAnnotationType associated with this JAnnotation
Referenced by org.exolab.javasource.JStructure.addImport().
String [] org.exolab.javasource.JAnnotation.getElementNames | ( | ) |
Returns the names of the elements set by this annotation
References org.exolab.castor.util.OrderedHashMap.keySet().
Referenced by org.exolab.javasource.JAnnotation.print().
String org.exolab.javasource.JAnnotation.getElementValue | ( | String | elementName | ) | throws IllegalStateException |
Returns the given annotation element value
elementName |
IllegalArgumentException | when the element value is not a String |
References org.exolab.javasource.JAnnotation.getElementValueObject().
JAnnotation org.exolab.javasource.JAnnotation.getElementValueAnnotation | ( | String | elementName | ) | throws IllegalStateException |
Returns the given annotation element value as a JAnnotation
elementValue |
IllegalArgumentException | when the element value is not a JAnnotation |
References org.exolab.javasource.JAnnotation.getElementValueObject().
JAnnotation [] org.exolab.javasource.JAnnotation.getElementValueAnnotationList | ( | String | elementName | ) | throws IllegalStateException |
Returns the given annotation element value as a JAnnotation list
elementValue |
IllegalArgumentException | when the element value is not a JAnnotation[] |
References org.exolab.javasource.JAnnotation.getElementValueObject().
String [] org.exolab.javasource.JAnnotation.getElementValueList | ( | String | elementName | ) | throws IllegalStateException |
Returns the given annotation element value as a list
elementName |
IllegalArgumentException | when the element value is not a String[] |
References org.exolab.javasource.JAnnotation.getElementValueObject().
Object org.exolab.javasource.JAnnotation.getElementValueObject | ( | String | elementName | ) |
Returns the given annotation element value as Object, typically used if the value type is not known. This will either be a String or JAnnotation as single value or as an array.
elementName |
Referenced by org.exolab.javasource.JAnnotation.getElementValue(), org.exolab.javasource.JAnnotation.getElementValueAnnotation(), org.exolab.javasource.JAnnotation.getElementValueAnnotationList(), org.exolab.javasource.JAnnotation.getElementValueList(), org.exolab.javasource.JAnnotation.getValue(), org.exolab.javasource.JAnnotation.getValueAnnotation(), and org.exolab.javasource.JAnnotation.print().
String org.exolab.javasource.JAnnotation.getValue | ( | ) |
Returns the "value" annotation element value
IllegalStateException | when the element value is not a String |
References org.exolab.javasource.JAnnotation.getElementValueObject(), and org.exolab.javasource.JAnnotation.value.
JAnnotation org.exolab.javasource.JAnnotation.getValueAnnotation | ( | ) | throws IllegalStateException |
Returns the "value" annotation element value as an JAnnotation
IllegalStateException | when the element value is not a JAnnotation |
References org.exolab.javasource.JAnnotation.getElementValueObject(), and org.exolab.javasource.JAnnotation.value.
static void org.exolab.javasource.JAnnotation.main | ( | String[] | args | ) | [static] |
args |
References org.exolab.javasource.JSourceWriter.flush(), org.exolab.javasource.JAnnotation.JAnnotation(), org.exolab.javasource.JAnnotation.print(), org.exolab.javasource.JAnnotation.setElementValue(), org.exolab.javasource.JAnnotation.setValue(), and org.exolab.javasource.JSourceWriter.writeln().
void org.exolab.javasource.JAnnotation.print | ( | JSourceWriter | jsw | ) |
Prints the source code for this JAnnotation to the given JSourceWriter
jsw | the JSourceWriter to print to. [May not be null] |
References org.exolab.javasource.JAnnotation.getElementNames(), org.exolab.javasource.JAnnotation.getElementValueObject(), org.exolab.javasource.JType.getLocalName(), org.exolab.javasource.JSourceWriter.indent(), org.exolab.javasource.JSourceWriter.unindent(), org.exolab.javasource.JAnnotation.value, org.exolab.javasource.JSourceWriter.write(), and org.exolab.javasource.JSourceWriter.writeln().
Referenced by org.exolab.javasource.JAnnotation.main().
void org.exolab.javasource.JAnnotation.setElementValue | ( | String | elementName, | |
JAnnotation | annotationValue | |||
) |
Sets the given annotation element value as an annotation
elementName | ||
annotationValue |
References org.exolab.castor.util.OrderedHashMap.put().
void org.exolab.javasource.JAnnotation.setElementValue | ( | String | elementName, | |
JAnnotation[] | annotationValues | |||
) |
Sets the given annotation element values as a list of annotation values
elementName | ||
annotationValue |
References org.exolab.castor.util.OrderedHashMap.put().
void org.exolab.javasource.JAnnotation.setElementValue | ( | String | elementName, | |
String[] | stringValues | |||
) |
Sets the given annotation element value as a list
elementName | ||
stringValue |
References org.exolab.castor.util.OrderedHashMap.put().
void org.exolab.javasource.JAnnotation.setElementValue | ( | String | elementName, | |
String | stringValue | |||
) |
Sets the given annotation element value
elementName | ||
stringValue |
References org.exolab.castor.util.OrderedHashMap.put().
Referenced by org.exolab.javasource.JAnnotation.main().
void org.exolab.javasource.JAnnotation.setValue | ( | JAnnotation[] | annotationValues | ) |
Sets the "value" annotation element value as a list of annotation values
annotationValue |
References org.exolab.castor.util.OrderedHashMap.put(), and org.exolab.javasource.JAnnotation.value.
void org.exolab.javasource.JAnnotation.setValue | ( | String | stringValue | ) |
Sets the "value" annotation element value
stringValue |
References org.exolab.castor.util.OrderedHashMap.put(), and org.exolab.javasource.JAnnotation.value.
Referenced by org.exolab.javasource.JAnnotation.main().
void org.exolab.javasource.JAnnotation.setValue | ( | String[] | stringValue | ) |
Sets the "value" annotation element value as a list
stringValue |
References org.exolab.castor.util.OrderedHashMap.put(), and org.exolab.javasource.JAnnotation.value.
void org.exolab.javasource.JAnnotation.setValue | ( | JAnnotation | annotationValue | ) |
Sets the "value" annotation element value as an annotation
annotationValue |
References org.exolab.castor.util.OrderedHashMap.put(), and org.exolab.javasource.JAnnotation.value.
final String org.exolab.javasource.JAnnotation.value = "value" [static] |
Name of a single element
Referenced by org.exolab.javasource.JAnnotation.getValue(), org.exolab.javasource.JAnnotation.getValueAnnotation(), org.exolab.javasource.JAnnotation.print(), and org.exolab.javasource.JAnnotation.setValue().