PsiElement (@NotNull PsiElement anchor) { if (anchor instanceof PsiIdentifier) { PsiElement parent = anchor.getParent(); if (parent instanceof PsiJavaCodeReferenceElement) { // anonymous class, type parent = parent.getParent(); } return parent; } if (anchor instanceof PsiJavaFile) { return ((PsiJavaFile)anchor).getImportList(); } return null; }