PsiField (@NotNull PsiElement entry) { PsiElement element = entry; while (element != null) { PsiElement parent = element.getParent(); if (parent instanceof PsiField field) { if (element == field.getInitializer()) return field; if (field instanceof PsiEnumConstant enumConstant && element == enumConstant.getArgumentList()) return field; } if (element instanceof PsiClass || element instanceof PsiMethod) return null; element = parent; } return null; }