Class AnnotationValueImpl

  • All Implemented Interfaces:
    JAnnotationValue

    public class AnnotationValueImpl
    extends java.lang.Object
    implements JAnnotationValue

    Implementation of JAnnotationValue

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      JAnnotation asAnnotation()
      If this member is complex (i.e.
      JAnnotation[] asAnnotationArray()
      If this member is known to be an array of annotations (i.e.
      boolean asBoolean()
      Returns the member's value as a boolean.
      boolean[] asBooleanArray()
      Returns this member's value as an array of booleans.
      byte asByte()
      Returns the member's value as a byte.
      byte[] asByteArray()
      Returns this member's value as an array of bytes.
      char asChar()
      Returns the member's value as a char.
      char[] asCharArray()
      Returns this member's value as an array of bytes.
      JClass asClass()
      Returns the value of this member as a JClass.
      JClass[] asClassArray()
      If this member is known to be an array of classes, returns an array of JClass representations of those classes.
      double asDouble()
      Returns the member's value as a double.
      double[] asDoubleArray()
      Returns this member's value as an array of doubles.
      float asFloat()
      Returns the member's value as a float.
      float[] asFloatArray()
      Returns this member's value as an array of floats.
      int asInt()
      Returns the member's value as an int.
      int[] asIntArray()
      Returns this member's value as an array of ints.
      long asLong()
      Returns the member's value as a long.
      long[] asLongArray()
      Returns this member's value as an array of longs.
      short asShort()
      Returns the member's value as a short.
      short[] asShortArray()
      Returns this member's value as an array of shorts.
      java.lang.String asString()
      Returns the String value of the annotation.
      java.lang.String[] asStringArray()
      Returns this member's value as an array of Strings.
      java.lang.String getName()  
      JClass getType()  
      java.lang.Object getValue()  
      boolean isDefaultValueUsed()
      Returns true if the member's value was not explicitly set in the annotation instance but was instead taken from the member definition's default.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AnnotationValueImpl

        public AnnotationValueImpl​(ElementContext ctx,
                                   java.lang.String name,
                                   java.lang.Object value,
                                   JClass type)
    • Method Detail

      • isDefaultValueUsed

        public boolean isDefaultValueUsed()
        Description copied from interface: JAnnotationValue

        Returns true if the member's value was not explicitly set in the annotation instance but was instead taken from the member definition's default.

        Note that not all JAM implementations may be able to distinguish the case where the value is explicitly declared to be the same value as the member's default from the case where the value is not declared and the value is implicitly default. In this event, this method will return true if and only if the effective value of the annotation is the same as the default value (regardless of how that value was declared).

        Specified by:
        isDefaultValueUsed in interface JAnnotationValue
      • asAnnotation

        public JAnnotation asAnnotation()
        Description copied from interface: JAnnotationValue

        If this member is complex (i.e. an instance of another annotation type), this method returns a representation of the annotation instance. Returns null in all other samples. This method always returns null if the annotation is a javdoc tag, as such tags only support one level of nesting.

        Specified by:
        asAnnotation in interface JAnnotationValue
      • asClass

        public JClass asClass()
        Description copied from interface: JAnnotationValue

        Returns the value of this member as a JClass. Returns null if the value cannot be understood as a class name or if the type of the member is known to be something other than java.lang.Class.

        Specified by:
        asClass in interface JAnnotationValue
      • asString

        public java.lang.String asString()
        Description copied from interface: JAnnotationValue

        Returns the String value of the annotation. If the value is known to be a simple, non-array type other than String, it will be converted in a resonable manner (with an appropriate toString() or String.valueOf() method). If the value is known to be complex or is an array, this method will return null.

        If no type information is available for the annotation member (i.e. it's a javadoc tag), then the raw textual value of the member is returned.

        Specified by:
        asString in interface JAnnotationValue
      • asInt

        public int asInt()
                  throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns the member's value as an int. If the value is not known to be an int, (because it's a javadoc tag or because it's a 175 annotation member of a type other than int) asString() is called. If the result is null, NumberFormatException is thrown. Otherwise, the String is converted to an int with Integer.valueOf(), which again may throw NumberFormatException.

        Specified by:
        asInt in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asBoolean

        public boolean asBoolean()
                          throws java.lang.IllegalArgumentException
        Description copied from interface: JAnnotationValue

        Returns the member's value as a boolean. If necessary, type conversion is performed in a similar manner as described for asInt(), except that IllegalArgumentException is thrown instead of NumberFormatException.

        Specified by:
        asBoolean in interface JAnnotationValue
        Throws:
        java.lang.IllegalArgumentException
      • asLong

        public long asLong()
                    throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns the member's value as a long. If necessary, type conversion is performed in a similar manner as described for asInt().

        Specified by:
        asLong in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asShort

        public short asShort()
                      throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns the member's value as a short. If necessary, type conversion is performed in a similar manner as described for asInt().

        Specified by:
        asShort in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asDouble

        public double asDouble()
                        throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns the member's value as a double. If necessary, type conversion is performed in a similar manner as described for asInt().

        Specified by:
        asDouble in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asFloat

        public float asFloat()
                      throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns the member's value as a float. If necessary, type conversion is performed in a similar manner as described for asInt().

        Specified by:
        asFloat in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asByte

        public byte asByte()
                    throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns the member's value as a byte. If necessary, type conversion is performed in a similar manner as described for asInt().

        Specified by:
        asByte in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asChar

        public char asChar()
                    throws java.lang.IllegalArgumentException
        Description copied from interface: JAnnotationValue

        Returns the member's value as a char. If necessary, type conversion is performed by calling getStringValue(). If the result is null or is a String that is not exactly of length 1, IllegalArgumentException is thrown.

        Specified by:
        asChar in interface JAnnotationValue
        Throws:
        java.lang.IllegalArgumentException
      • asClassArray

        public JClass[] asClassArray()
        Description copied from interface: JAnnotationValue

        If this member is known to be an array of classes, returns an array of JClass representations of those classes. If the memeber is known to be an array of a simple non-array type, this method will call asStringArray() and attempt to return a JClass by treating each string in the returned array as a qualified classname. Returns null otherwise.

        This method always returns null for javadoc tags.

        Specified by:
        asClassArray in interface JAnnotationValue
      • asAnnotationArray

        public JAnnotation[] asAnnotationArray()
        Description copied from interface: JAnnotationValue

        If this member is known to be an array of annotations (i.e. complex, nested types), this method returns an array containing each complex value as a JAnnotation. Returns null in all other samples.

        This method always returns null for javadoc tags.

        Specified by:
        asAnnotationArray in interface JAnnotationValue
      • asStringArray

        public java.lang.String[] asStringArray()
        Description copied from interface: JAnnotationValue

        Returns this member's value as an array of Strings. If this member is not of an array type, or is an array of arrays or complex annotations, this method returns null. If it is an array of a simple, non-array type other than String, conversion on each component will be attempted as described under getStringValue().

        This method always returns null for javadoc tags.

        Specified by:
        asStringArray in interface JAnnotationValue
      • asIntArray

        public int[] asIntArray()
                         throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns this member's value as an array of ints. If this member is not of an array type, or is an array of arrays or complex annotations, this method returns null. If it is an array of a simple, non-array type other than int, conversion on each component will be attempted as described under getIntValue().

        This method always returns null for javadoc tags.

        Specified by:
        asIntArray in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asBooleanArray

        public boolean[] asBooleanArray()
                                 throws java.lang.IllegalArgumentException
        Description copied from interface: JAnnotationValue

        Returns this member's value as an array of booleans. If necessary, type conversion is performed in a similar manner as described for asIntArray(), except that IllegalArgumentException may be thrown instead of NumberFormatException.

        This method always returns null for javadoc tags.

        Specified by:
        asBooleanArray in interface JAnnotationValue
        Throws:
        java.lang.IllegalArgumentException
      • asShortArray

        public short[] asShortArray()
                             throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns this member's value as an array of shorts. If necessary, type conversion is performed in a similar manner as described for asIntArray().

        This method always returns null for javadoc tags.

        Specified by:
        asShortArray in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asLongArray

        public long[] asLongArray()
                           throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns this member's value as an array of longs. If necessary, type conversion is performed in a similar manner as described for asIntArray().

        This method always returns null for javadoc tags.

        Specified by:
        asLongArray in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asDoubleArray

        public double[] asDoubleArray()
                               throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns this member's value as an array of doubles. If necessary, type conversion is performed in a similar manner as described for asIntArray().

        This method always returns null for javadoc tags.

        Specified by:
        asDoubleArray in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asFloatArray

        public float[] asFloatArray()
                             throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns this member's value as an array of floats. If necessary, type conversion is performed in a similar manner as described for asIntArray().

        This method always returns null for javadoc tags.

        Specified by:
        asFloatArray in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asByteArray

        public byte[] asByteArray()
                           throws java.lang.NumberFormatException
        Description copied from interface: JAnnotationValue

        Returns this member's value as an array of bytes. If necessary, type conversion is performed in a similar manner as described for asIntArray().

        This method always returns null for javadoc tags.

        Specified by:
        asByteArray in interface JAnnotationValue
        Throws:
        java.lang.NumberFormatException
      • asCharArray

        public char[] asCharArray()
                           throws java.lang.IllegalArgumentException
        Description copied from interface: JAnnotationValue

        Returns this member's value as an array of bytes. If necessary, type conversion is performed in a similar manner as described for asIntArray() and asChar()..

        This method always returns null for javadoc tags.

        Specified by:
        asCharArray in interface JAnnotationValue
        Throws:
        java.lang.IllegalArgumentException