List<PsiNameIdentifierOwner> (PsiElement element, boolean findFirstOnly) { element = element.getParent(); List<PsiNameIdentifierOwner> parents = new SmartList<>(); while (element != null) { if (element instanceof PsiField && ((PsiField)element).hasModifierProperty(PsiModifier.STATIC)) { break; } if (element instanceof PsiClass && ((PsiClass)element).isEnum()) break; if (element instanceof PsiMethod || isValidClass(element)) { if (((PsiMember)element).getName() != null) { parents.add((PsiNameIdentifierOwner)element); if (findFirstOnly) { return parents; } } if (((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC)) break; } element = element.getParent(); } return parents; }