return node.getElement();
}
@Override
public Element visitIdentifier(Identifier node) {
AstNode parent = node.getParent();
// Type name in Annotation
if (parent instanceof Annotation) {
Annotation annotation = (Annotation) parent;
if (annotation.getName() == node && annotation.getConstructorName() == null) {
return annotation.getElement();
}
}
// Extra work to map Constructor Declarations to their associated Constructor Elements
if (parent instanceof ConstructorDeclaration) {
ConstructorDeclaration decl = (ConstructorDeclaration) parent;
Identifier returnType = decl.getReturnType();
if (returnType == node) {
SimpleIdentifier name = decl.getName();
if (name != null) {
return name.getBestElement();
}
Element element = node.getBestElement();
if (element instanceof ClassElement) {
return ((ClassElement) element).getUnnamedConstructor();
}
}
}
if (parent instanceof LibraryIdentifier) {
AstNode grandParent = ((LibraryIdentifier) parent).getParent();
if (grandParent instanceof PartOfDirective) {
Element element = ((PartOfDirective) grandParent).getElement();
if (element instanceof LibraryElement) {
return ((LibraryElement) element).getDefiningCompilationUnit();
}