Element class

The base class for all of the elements in the element model. Generally speaking, the element model is a semantic model of the program that represents things that are declared with a name and hence can be referenced elsewhere in the code.

There are two exceptions to the general case. First, there are elements in the element model that are created for the convenience of various kinds of analysis but that do not have any corresponding declaration within the source code. Such elements are marked as being synthetic. Examples of synthetic elements include

  • default constructors in classes that do not define any explicit constructors,
  • getters and setters that are induced by explicit field declarations,
  • fields that are induced by explicit declarations of getters and setters, and
  • functions representing the initialization expression for a variable.

Second, there are elements in the element model that do not have a name. These correspond to unnamed functions and exist in order to more accurately represent the semantic structure of the program.

Clients may not extend, implement or mix-in this class.

Implemented types
Implementers

Constructors

Element()

Properties

context → AnalysisContext
Return the analysis context in which this element is defined.
read-only
displayName → String
Return the display name of this element, or null if this element does not have a name. [...]
read-only
documentationComment → String
Return the content of the documentation comment (including delimiters) for this element, or null if this element does not or cannot have documentation.
read-only
enclosingElement Element
Return the element that either physically or logically encloses this element. This will be null if this element is a library because libraries are the top-level elements in the model.
read-only
hasAlwaysThrows → bool
Return true if this element has an annotation of the form @alwaysThrows.
read-only
hasDeprecated → bool
Return true if this element has an annotation of the form @deprecated or @Deprecated('..').
read-only
hasFactory → bool
Return true if this element has an annotation of the form @factory.
read-only
hasIsTest → bool
Return true if this element has an annotation of the form @isTest.
read-only
hasIsTestGroup → bool
Return true if this element has an annotation of the form @isTestGroup.
read-only
hasJS → bool
Return true if this element has an annotation of the form @JS(..).
read-only
hasLiteral → bool
Return true if this element has an annotation of the form '@literal'.
read-only
hasOverride → bool
Return true if this element has an annotation of the form @override.
read-only
hasProtected → bool
Return true if this element has an annotation of the form @protected.
read-only
hasRequired → bool
Return true if this element has an annotation of the form '@required'.
read-only
hasSealed → bool
Return true if this element has an annotation of the form '@sealed'.
read-only
hasVisibleForTemplate → bool
Return true if this element has an annotation of the form @visibleForTemplate.
read-only
hasVisibleForTesting → bool
Return true if this element has an annotation of the form @visibleForTesting.
read-only
id → int
The unique integer identifier of this element.
read-only
isAlwaysThrows → bool
Return true if this element has an annotation of the form '@alwaysThrows'.
read-only
isDeprecated → bool
Return true if this element has an annotation of the form '@deprecated' or '@Deprecated('..')'.
read-only
isFactory → bool
Return true if this element has an annotation of the form '@factory'.
read-only
isJS → bool
Return true if this element has an annotation of the form '@JS(..)'.
read-only
isOverride → bool
Return true if this element has an annotation of the form '@override'.
read-only
isPrivate → bool
Return true if this element is private. Private elements are visible only within the library in which they are declared.
read-only
isProtected → bool
Return true if this element has an annotation of the form '@protected'.
read-only
isPublic → bool
Return true if this element is public. Public elements are visible within any library that imports the library in which they are declared.
read-only
isRequired → bool
Return true if this element has an annotation of the form '@required'.
read-only
isSynthetic → bool
Return true if this element is synthetic. A synthetic element is an element that is not represented in the source code explicitly, but is implied by the source code, such as the default constructor for a class that does not explicitly define any constructors.
read-only
isVisibleForTesting → bool
Return true if this element has an annotation of the form '@visibleForTesting'.
read-only
kind ElementKind
Return the kind of element that this is.
read-only
library LibraryElement
Return the library that contains this element. This will be the element itself if it is a library element. This will be null if this element is an HTML file because HTML files are not contained in libraries.
read-only
location ElementLocation
Return an object representing the location of this element in the element model. The object can be used to locate this element at a later time.
read-only
metadata → List<ElementAnnotation>
Return a list containing all of the metadata associated with this element. The array will be empty if the element does not have any metadata or if the library containing this element has not yet been resolved.
read-only
name → String
Return the name of this element, or null if this element does not have a name.
read-only
nameLength → int
Return the length of the name of this element in the file that contains the declaration of this element, or 0 if this element does not have a name.
read-only
nameOffset → int
Return the offset of the name of this element in the file that contains the declaration of this element, or -1 if this element is synthetic, does not have a name, or otherwise does not have an offset.
read-only
session AnalysisSession
Return the analysis session in which this element is defined.
read-only
source → Source
Return the source associated with this target, or null if this target is not associated with a source.
read-only, override
unit CompilationUnit
Return the resolved CompilationUnit that declares this element, or null if this element is synthetic. [...]
read-only
hashCode → int
The hash code for this object.
read-only, inherited
librarySource → Source
If this target is associated with a library, return the source of the library's defining compilation unit; otherwise return null.
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

accept<T>(ElementVisitor<T> visitor) → T
Use the given visitor to visit this element. Return the value returned by the visitor as a result of visiting this element.
computeDocumentationComment() → String
Return the documentation comment for this element as it appears in the original source (complete with the beginning and ending delimiters), or null if this element does not have a documentation comment associated with it. This can be a long-running operation if the information needed to access the comment is not cached. [...]
computeNode() AstNode
Return the resolved AstNode node that declares this element, or null if this element is synthetic or isn't contained in a compilation unit, such as a LibraryElement. [...]
getAncestor<E extends Element>(Predicate<Element> predicate) → E
Return the most immediate ancestor of this element for which the predicate returns true, or null if there is no such ancestor. Note that this element will never be returned.
getExtendedDisplayName(String shortName) → String
Return a display name for the given element that includes the path to the compilation unit in which the type is defined. If shortName is null then displayName will be used as the name of this element. Otherwise the provided name will be used.
isAccessibleIn(LibraryElement library) → bool
Return true if this element, assuming that it is within scope, is accessible to code in the given library. This is defined by the Dart Language Specification in section 3.2: [...]
visitChildren(ElementVisitor visitor) → void
Use the given visitor to visit all of the children of this element. There is no guarantee of the order in which the children will be visited.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator.
inherited

Static Properties

SORT_BY_OFFSET → Comparator<Element>
A comparator that can be used to sort elements by their name offset. Elements with a smaller offset will be sorted to be before elements with a larger name offset.
final