getElement method
Returns the element associated with this.
If useMockForImport is true then a MockLibraryImportElement will be
returned when an import directive or a prefix element is associated with
this. The rename-prefix refactoring should be updated to not require
this work-around.
Returns null if this is null or doesn't have an element.
Implementation
Element? getElement({bool useMockForImport = false}) {
AstNode? node = this;
if (node is SimpleIdentifier && node.parent is LibraryIdentifier) {
node = node.parent;
}
if (node is LibraryIdentifier) {
node = node.parent;
}
if (node is StringLiteral && node.parent is UriBasedDirective) {
return null;
}
Element? element;
if (useMockForImport && node is ImportDirective) {
element = MockLibraryImportElement(node.libraryImport!);
} else {
element = ElementLocator.locate(node);
}
if (useMockForImport &&
node is SimpleIdentifier &&
element is PrefixElement) {
element = MockLibraryImportElement(getImportElement(node)!);
}
return element;
}