PsiJavaCodeReferenceElement (@Nullable PsiElement position) { PsiAnnotation anno = PsiTreeUtil.getParentOfType(position, PsiAnnotation.class); PsiJavaCodeReferenceElement ref = anno == null ? null : anno.getNameReferenceElement(); return ref != null && PsiTreeUtil.isAncestor(ref, position, false) ? ref : null; }