PsiClass (PsiElement occurrence) { PsiElement cur = occurrence; while (true) { final PsiClass parentClass = PsiTreeUtil.getParentOfType(cur, PsiClass.class, true); if (parentClass == null || parentClass.hasModifierProperty(PsiModifier.STATIC)) return parentClass; cur = parentClass; } }