PsiElement (final PsiElement element, PsiFileSystemItem item, int refIndex) { if (item != null && item.isValid() && item.getVirtualFile() != null) { PsiReference[] refs = element.getReferences(); if (refIndex >= 0 && refs.length > refIndex) { PsiReference ref = refs[refIndex]; if (ref instanceof FileReferenceOwner) { PsiElement result = bindAndCheckElement(ref, element, item); if (result != null) return result; } } for (PsiReference ref : refs) { if (ref instanceof FileReferenceOwner) { PsiElement result = bindAndCheckElement(ref, element, item); if (result != null) return result; break; } } } return element; }