Interface IAnnotation
- All Superinterfaces:
org.eclipse.core.runtime.IAdaptable, IJavaElement, ISourceReference
- All Known Implementing Classes:
Annotation, AssistAnnotation
Annotations are obtained using IAnnotatable.getAnnotation(String).
Note that annotations are not children of their declaring element.
To get a list of the annotations use IAnnotatable.getAnnotations().
- Since:
- 3.4
-
Field Summary
Fields inherited from interface IJavaElement
ANNOTATION, CLASS_FILE, COMPILATION_UNIT, FIELD, IMPORT_CONTAINER, IMPORT_DECLARATION, INITIALIZER, JAVA_MODEL, JAVA_MODULE, JAVA_PROJECT, LOCAL_VARIABLE, METHOD, PACKAGE_DECLARATION, PACKAGE_FRAGMENT, PACKAGE_FRAGMENT_ROOT, TYPE, TYPE_PARAMETERModifier and TypeFieldDescriptionstatic final intConstant representing an annotation.static final intConstant representing a class file.static final intConstant representing a Java compilation unit.static final intConstant representing a field.static final intConstant representing all import declarations within a compilation unit.static final intConstant representing an import declaration within a compilation unit.static final intConstant representing a stand-alone instance or class initializer.static final intConstant representing a Java model (workspace level object).static final intConstant represents a module descriptor.static final intConstant representing a Java project.static final intConstant representing a local variable declaration.static final intConstant representing a method or constructor.static final intConstant representing a package declaration within a compilation unit.static final intConstant representing a package fragment.static final intConstant representing a package fragment root.static final intConstant representing a type (a class or interface).static final intConstant representing a type parameter declaration. -
Method Summary
Modifier and TypeMethodDescriptionReturns the name of this annotation.Returns the member-value pairs of this annotation.intReturns the position relative to the order this annotation is defined in the source.Methods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapterMethods inherited from interface IJavaElement
exists, getAncestor, getAttachedJavadoc, getCorrespondingResource, getElementType, getHandleIdentifier, getJavaModel, getJavaProject, getOpenable, getParent, getPath, getPrimaryElement, getResource, getSchedulingRule, getUnderlyingResource, isReadOnly, isStructureKnownModifier and TypeMethodDescriptionbooleanexists()Returns whether this Java element exists in the model.getAncestor(int ancestorType) Returns this Java element or the first ancestor of this element that has the given type.getAttachedJavadoc(org.eclipse.core.runtime.IProgressMonitor monitor) Returns the Javadoc as HTML source if this element has attached Javadoc,nullotherwise.org.eclipse.core.resources.IResourceReturns the resource that corresponds directly to this element, ornullif there is no resource that corresponds to this element.intReturns this element's kind encoded as an integer.Returns a string representation of this element handle.Returns the Java model.Returns the Java project this element is contained in, ornullif this element is not contained in any Java project (for instance, theIJavaModelis not contained in any Java project).Returns the first openable parent.Returns the element directly containing this element, ornullif this element has no parent.org.eclipse.core.runtime.IPathgetPath()Returns the path to the innermost resource enclosing this element.Returns the primary element (whose compilation unit is the primary compilation unit) this working copy element was created from, or this element if it is a descendant of a primary compilation unit or if it is not a descendant of a working copy (e.g.org.eclipse.core.resources.IResourceReturns the innermost resource enclosing this element.org.eclipse.core.runtime.jobs.ISchedulingRuleReturns the scheduling rule associated with this Java element.org.eclipse.core.resources.IResourceReturns the smallest underlying resource that contains this element, ornullif this element is not contained in a resource.booleanReturns whether this Java element is read-only.booleanReturns whether the structure of this element is known.Methods inherited from interface ISourceReference
exists, getNameRange, getSource, getSourceRangeModifier and TypeMethodDescriptionbooleanexists()Returns whether this element exists in the model.Returns the name range associated with this element.Returns the source code associated with this element.Returns the source range associated with this element.
-
Method Details
-
getElementName
String getElementName()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
ISourceReference.getNameRange().This is a handle-only method. The annotation may or may not be present.
- Specified by:
getElementNamein interfaceIJavaElement- Returns:
- the name of this annotation
-
getMemberValuePairs
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".- Returns:
- 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
-
getOccurrenceCount
int getOccurrenceCount()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.
- Returns:
- the position relative to the order this annotation is defined in the source
-