Class JAnnotationType

  • All Implemented Interfaces:
    JAnnotatedElement

    public final class JAnnotationType
    extends JStructure
    Describes the definition of a annotation type class.
       JAnnotationType type = new JAnnotationType("RequestForEnhancement");
       type.addElement(new JAnnotationTypeElement("id", JType.Int));
       type.addElement(new JAnnotationTypeElement("synopsis", new JType("String")));
       JAnnotationTypeElement engineer;
       engineer = new JAnnotationTypeElement("engineer", new JType("String"));
       engineer.setDefaultString("\"[unassigned]\"");
       type.addElement(engineer);
       JAnnotationTypeElement date;
       date = new JAnnotationTypeElement("date", new JType("String"));
       date.setDefaultString("\"[unimplemented]\"");
       type.addElement(date);
     
    outputs
       public @interface RequestForEnhancement {
           int id();
           String synopsis();
           String engineer() default "[unassigned]";
           String date() default "[unimplemented]";
       }
     
    Version:
    $Revision: 8130 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
    Author:
    Andrew Fawcett
    • Constructor Detail

      • JAnnotationType

        public JAnnotationType​(java.lang.String name)
        Creates a JAnnotationType of the given name.
        Parameters:
        name - Annotation name.
    • Method Detail

      • addImport

        public void addImport​(java.lang.String className)
        Adds the given import to this JStructure. Note: You cannot import from the "default package," so imports with no package are ignored.
        Specified by:
        addImport in class JStructure
        Parameters:
        className - Name of the class to import.
      • addMember

        public void addMember​(JMember jMember)
        Adds the given JMember to this JAnnotationType.
        Specified by:
        addMember in class JStructure
        Parameters:
        jMember - The JMember to add.
      • getElements

        public JAnnotationTypeElement[] getElements()
        Returns an Array containing all our JAnnotationTypeElements.
        Returns:
        An Array containing all our JAnnotationTypeElements.
      • getElement

        public JAnnotationTypeElement getElement​(java.lang.String name)
        Returns the member with the given name, or null if no member was found with the given name.
        Parameters:
        name - The name of the member to return.
        Returns:
        The member with the given name, or null if no member was found with the given name.
      • addElement

        public void addElement​(JAnnotationTypeElement jElement)
        Adds the given JAnnotationTypeElement to this JAnnotationType.
        Parameters:
        jElement - The element to add.
      • getFields

        public JField[] getFields()
        Not implemented. Always throws a RuntimeException.
        Returns an array of all the JFields of this JStructure.
        Specified by:
        getFields in class JStructure
        Returns:
        An array of all the JFields of this JStructure.
      • getField

        public JField getField​(java.lang.String name)
        Not implemented. Always throws a RuntimeException.
        Returns the field with the given name, or null if no field was found with that name.
        Specified by:
        getField in class JStructure
        Parameters:
        name - The name of the field to return.
        Returns:
        The field with the given name, or null if no field was found with the given name.
      • addField

        public void addField​(JField jField)
        Not implemented. Always throws a RuntimeException.
        Adds the given JField to this JStructure.
        This method is implemented by subclasses and should only accept the proper fields for the subclass otherwise an IllegalArgumentException will be thrown. For example a JInterface will only accept static fields.
        Specified by:
        addField in class JStructure
        Parameters:
        jField - The JField to add.