referenceElement property

Element? referenceElement

This element is set when this identifier is used not as an expression, but just to reference some element.

Examples are the name of the type in a NamedType, the name of the method in a MethodInvocation, the name of the constructor in a ConstructorName, the name of the property in a PropertyAccess, the prefix and the identifier in a PrefixedIdentifier (which then can be used to read or write a value).

In invalid code, for recovery, any element could be used, e.g. a setter as a type name set mySetter(_) {} mySetter topVar;. We do this to help the user to navigate to this element, and maybe change its name, add a new declaration, etc.

Return null if this identifier is used to either read or write a value, or the AST structure has not been resolved, or if this identifier could not be resolved.

If either readElement or writeElement are not null, the referenceElement is null, because the identifier is being used to read or write a value.

All three readElement, writeElement, and referenceElement can be null when the AST structure has not been resolved, or this identifier could not be resolved.

Implementation

Element? get referenceElement => null;