PsiJavaCodeReferenceElement (@Nullable PsiJavaCodeReferenceElement ref) { if (ref == null) return null; PsiElement qualifier; while ((qualifier = ref.getQualifier()) instanceof PsiJavaCodeReferenceElement) { ref = (PsiJavaCodeReferenceElement)qualifier; } return ref; }