PsiElement (@NotNull PsiElement element) { if (element instanceof PsiIdentifier) { PsiElement parent = element.getParent(); if (parent instanceof PsiClass && element.equals(((PsiClass)parent).getNameIdentifier()) || parent instanceof PsiVariable && element.equals(((PsiVariable)parent).getNameIdentifier()) || parent instanceof PsiMethod && element.equals(((PsiMethod)parent).getNameIdentifier()) || parent instanceof PsiLabeledStatement && element.equals(((PsiLabeledStatement)parent).getLabelIdentifier())) { return parent; } if (parent instanceof PsiJavaModuleReferenceElement) { PsiElement grand = parent.getParent(); if (grand instanceof PsiJavaModule) { return grand; } } } return null; }