/** * Represents an annotation on a package declaration, a type, a method, a field * or a local variable in a compilation unit or a class file. *
* Annotations are obtained using {@link IAnnotatable#getAnnotation(String)}. *
* Note that annotations are not children of their declaring element. * To get a list of the annotations use {@link IAnnotatable#getAnnotations()}. *
** This interface is not intended to be implemented or extended by clients. *
* * @since 3.4 */ public interface IAnnotation extends IJavaElement, ISourceReference { /** * Returns the name of this annotation. If this annotation is coming from * a compilation unit, this is either a simple name (e.g. for@MyAnnot
, the name
* is "MyAnnot"), or a qualified name (e.g. for @x. y. MyAnnot
, the name is
* "x.y.MyAnnot"). If this annotation is coming from a class file, this is always a fully
* qualified name.
* Note that the name has been trimmed from its whitespaces. To extract the name as it * appears in the source, use {@link #getNameRange()}. *
* This is a handle-only method. The annotation may or may not be present. *
* * @return the name of this annotation */ String getElementName(); /** * Returns the member-value pairs of this annotation. Returns an empty * array if this annotation is a marker annotation. Returns a size-1 array if this * annotation is a single member annotation. In this case, the member * name is always"value"
.
*
* @return the member-value pairs of this annotation
* @throws JavaModelException if this element does not exist or if an
* exception occurs while accessing its corresponding resource
*/
IMemberValuePair[] getMemberValuePairs() throws JavaModelException;
/**
* Returns the source range of this annotation's name,
* or null
if this annotation does not have
* associated source code (for example, in a binary type).
*
* @exception JavaModelException if this element does not exist or if an
* exception occurs while accessing its corresponding resource.
* @return the source range of this annotation's name,
* or null
if this annotation does not have
* associated source code (for example, in a binary type)
*/
ISourceRange getNameRange() throws JavaModelException;
/**
* Returns the position relative to the order this annotation is defined in the source.
* Numbering starts at 1 (thus the first occurrence is occurrence 1, not occurrence 0).
* * Two annotations ann1 and ann2 that are equal (e.g. 2 annotations with the same name on * the same type) can be distinguished using their occurrence counts. If annotation * ann1 appears first in the source, it will have an occurrence count of 1. If annotation * ann2 appears right after annotation ann1, it will have an occurrence count of 2. *
* This is a handle-only method. The annotation may or may not be present. *
* * @return the position relative to the order this annotation is defined in the source */ int getOccurrenceCount(); } /** * Represents a member-value pair of an annotation. * The {@link #getValue() value} is represented by an {@link Object}. To get the exact * instance if this object, use its {@link #getValueKind() value kind}. If this value is an array, * {@link #getValue()} returns an instance of {@link Object}[] and the value kind returns * the kind of the first element in this array. ** This interface is not intended to be implemented or extended by clients. *
* * @since 3.4 */ public interface IMemberValuePair { /** * Constant indicating that the value kind is anint
represented by
* an instance of {@link Integer}.
*/
int K_INT = 1;
/**
* Constant indicating that the value kind is a byte
represented by
* an instance of {@link Byte}.
*/
int K_BYTE = 2;
/**
* Constant indicating that the value kind is a short
represented by
* an instance of {@link Short}.
*/
int K_SHORT = 3;
/**
* Constant indicating that the value kind is a char
represented by
* an instance of {@link Character}.
*/
int K_CHAR = 4;
/**
* Constant indicating that the value kind is a float
represented by
* an instance of {@link Float}.
*/
int K_FLOAT = 5;
/**
* Constant indicating that the value kind is a double
represented by
* an instance of {@link Double}.
*/
int K_DOUBLE = 6;
/**
* Constant indicating that the value kind is a long
represented by
* an instance of {@link Long}.
*/
int K_LONG = 7;
/**
* Constant indicating that the value kind is a boolean
represented by
* an instance of {@link Boolean}.
*/
int K_BOOLEAN = 8;
/**
* Constant indicating that the value kind is a {@link String} represented by
* the corresponding {@link String}.
*/
int K_STRING = 9;
/**
* Constant indicating that the value kind is an annotation represented by
* an instance of {@link IAnnotation}.
*/
int K_ANNOTATION = 10;
/**
* Constant indicating that the value kind is a {@link Class} represented by
* the name of the class (i.e. a {@link String}. If the member-value pair is coming from
* a compilation unit, this is either a simple name (e.g. for MyType.class
,
* the name is "MyType"), or a qualified name (e.g. for x.y.MyType.class
,
* the name is "x.y.MyType"). If the member-value pair is coming from a class file, this is
* always a fully qualified name.
* * Note that one can use {@link IType#resolveType(String)} to find the corresponding * {@link IType}. *
*/ int K_CLASS = 11; /** * Constant indicating that the value is a qualified name represented by a {@link String}. * This usually represents an enumeration's constant (e.g. "MyEnum.FIRST"), but this * would need to be further analysed to ensure that. */ int K_QUALIFIED_NAME = 12; /** * Constant indicating that the value kind is unknown at this stage. This usually means that the * value is an expression that would need to be further analysed to determine its kind. For * example, in@MyAnnot(1 + 2.3)
the kind of the expression "1 + 2.3" is
* unknown.
* In this case, the returned value is always null
.
*/
int K_UNKNOWN = 13;
/**
* Returns the member's name of this member-value pair.
*
* @return the member's name of this member-value pair.
*/
String getMemberName();
/**
* Returns the value of this member-value pair. The instance of this value
* is function of this member-value pair's {@link #getValueKind() value kind}. It is an
* instance of {@link Object}[] if the value is an array. It is null
if
* the value kind is {@link #K_UNKNOWN}.
*
* Note an array value can contain null
elements if their value kind is
* {@link #K_UNKNOWN}, or if the elements in the array are heterogeneous. In this
* case, the instance of the first element is function of the value kind, and all other
* elements are null
.
*
* This interface is not intended to be implemented by clients. *
* * @since 3.4 */ public interface IAnnotatable { /** * Returns the annotation with the given name declared on this element. * This is a handle-only method. The annotation may or may not exist. * * @param name the given simple name * @return the annotation with the given name declared on this element */ IAnnotation getAnnotation(String name); /** * Returns the annotations for this element. * Returns an empty array if this method has no annotations. * * @exception JavaModelException if this element does not exist or if an * exception occurs while accessing its corresponding resource. * @return the annotations of this element, * in the order declared in the source, or an empty array if none * @since 3.4 */ IAnnotation[] getAnnotations() throws JavaModelException; } public interface IField extends IMember, IAnnotatable { ... } public interface IMethod extends IMember, IAnnotatable { ... } public interface IType extends IMember, IAnnotatable { ... } public interface IPackageDeclaration extends IJavaElement, ISourceReference, IAnnotatable { ... } public interface ILocalVariable extends IJavaElement, ISourceReference, IAnnotatable { ... } public interface IJavaElement extends IAdaptable { ... /** * Constant representing an annotation. * A Java element with this type can be safely cast to {@link IAnnotation}. * @since 3.4 */ int ANNOTATION = 16; ... } public interface IJavaElementDelta { ... /** * Change flag indicating that the annotations of the element have changed. * This flag is only valid if the element is an {@link IAnnotatable}. * * @since 3.4 */ public int F_ANNOTATIONS = 0x400000; ... } /** * Common protocol for Java elements that have associated source code. * This set consists of {@link IClassFile}, {@link ICompilationUnit}, * {@link IPackageDeclaration}, {@link IImportDeclaration}, * {@link IImportContainer}, {@link IType}, {@link IField}, * {@link IMethod}, {@link IInitializer}, {@link ITypeParameter}, * and {@link IAnnotation}. *
* Note: For IClassFile
, IType
and other members
* derived from a binary type, the implementation returns source iff the
* element has attached source code.
*
* Source reference elements may be working copies if they were created from * a compilation unit that is a working copy. *
** This interface is not intended to be implemented by clients. *
* * @see IPackageFragmentRoot#attachSource(org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IProgressMonitor) */ public interface ISourceReference { ... }