@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
if (ref instanceof JSTextReference) {
final PsiElement element = ref.getElement();
final JSCallExpression call = PsiTreeUtil.getParentOfType(element, JSCallExpression.class);
final JSExpression expression = call != null ? call.getMethodExpression() : null;
if (expression instanceof JSReferenceExpression) {
JSReferenceExpression callee = (JSReferenceExpression)expression;
JSExpression qualifier = callee.getQualifier();
if (qualifier != null && "directive".equals(callee.getReferencedName()) &&
AngularIndexUtil.hasAngularJS(element.getProject())) {
return element;
}